Skip to content

Instantly share code, notes, and snippets.

View andreidiaconu90's full-sized avatar

Andrei Diaconu andreidiaconu90

  • Romania
View GitHub Profile
@andreidiaconu90
andreidiaconu90 / GetStudentDetails.Tests.cs
Created April 6, 2022 10:57
Medium.com - C# Mock multiple HttpClient calls support 3
_httpHandlerMock.Protected().Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(rm => rm.RequestUri.AbsoluteUri.EndsWith("/getStudentDetails/{identifier}"),
ItExpr.IsAny<CancellationToken> ()).ReturnsAsync(mockedStudentDetailsResponse));
_httpHandlerMock.Protected().Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.Is<HttpRequestMessage>(rm => rm.RequestUri.AbsoluteUri.EndsWith("/getStudentGrades/{identifier}"),
ItExpr.IsAny<CancellationToken> ()).ReturnsAsync(mockedStudentGradesResponse));
@andreidiaconu90
andreidiaconu90 / GetStudentData.Tests.cs
Last active April 6, 2022 10:56
Medium.com - C# Mock multiple HttpClient calls support 2
var mockedResponseMessage = new HttpResponseMessage {
StatusCode = HttpStatusCode.OK,
Content = new StringContent("mocked-response-data-as-string-here")
};
_httpHandlerMock
.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
@andreidiaconu90
andreidiaconu90 / GetStudentData.cs
Created April 6, 2022 10:43
Medium.com - C# Mock multiple HttpClient calls support 1
public async Task<StudentData> GetStudentData(string studentIdentifier)
{
var studentDetailsRequest = new HttpRequestMessage
{
RequestUri = new Uri($ "{_httpClient.BaseAddress}/getStudentDetails/{studentIdentifier}"),
Method = HttpMethod.Get,
};
var studentDetailsRawResponse = await _httpClient.SendAsync(studentDetailsRequest);
var studentGradesRequest = new HttpRequestMessage
@andreidiaconu90
andreidiaconu90 / complex-bash
Created September 28, 2020 12:27
complex-bash
#! /bin/bash
declare -r bucketName="aws-pipeline-bucket"
declare -r region="eu-west-1"
declare -r stackName="aws-pipeline"
declare -r pipelinesFolderPath="./aws-pipelines"
declare -r pathToTemplate="<the-path-of-the-pipeline-template>"
handleResponse() {
if [ $1 -eq 0 ]
@andreidiaconu90
andreidiaconu90 / simple-bash
Created September 28, 2020 12:23
simple-bash
aws cloudformation package --template-file ./my-pipeline-root.yml --output-template ./my-packed-pipeline.yml --s3-bucket $bucketName &&
aws cloudformation deploy --template-file ./my-packed-pipeline.yml --stack-name my-stack-name --capabilities CAPABILITY_NAMED_IAM --region <my-region>
@andreidiaconu90
andreidiaconu90 / packaged-template-file
Last active September 28, 2020 11:53
packaged-template-file
AWSTemplateFormatVersion: '2010-09-09'
Resources:
MyFirstPipeline:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: https://s3.eu-west-1.amazonaws.com/my-bucket-name/<some-random-guid>.template
MySecondPipeline:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: https://s3.eu-west-1.amazonaws.com/my-bucket-name/<some-random-guid>.template
@andreidiaconu90
andreidiaconu90 / root-template-file
Last active September 28, 2020 11:54
root-template-file
AWSTemplateFormatVersion: '2010-09-09'
Resources:
MyFirstpipeline:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: ./my-first-pipeline.yml
MySecondPipeline:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: ./my-second-pipeline.yml
@andreidiaconu90
andreidiaconu90 / cfn-role-serverless
Created September 21, 2020 07:23
cfn-role-serverless
service:my service
provider:
name: aws
runtime: nodejs12.x
region: my-region
profile: default
apiGateway:
binaryMediaTypes:
- "application/octet-stream"
@andreidiaconu90
andreidiaconu90 / tl-dr-pipeline-template.txt
Created September 21, 2020 07:05
tl-dr-pipeline-template
AWSTemplateFormatVersion: "2010-09-09"
Parameters:
BranchName:
Description: CodeCommit branch name
Type: String
Default: master
RepositoryName:
Description: CodeCommit repository name
Type: String
Default: my-codecommit-repository-name
@andreidiaconu90
andreidiaconu90 / default-serverless-example
Created September 18, 2020 10:29
default-serverless-example
service:my service
provider:
name: aws
runtime: nodejs12.x
region: my-region
profile: default
apiGateway:
binaryMediaTypes:
- "application/octet-stream"