示例#1
0
        public async Task CreateAccount_Run_Success()
        {
            // arrange
            var mock = new Mock <ILogger>();
            var createAccountFunction = new CreateAccount(_mediatorService);
            var createAccountRequest  = new HttpRequestMessage
            {
                Headers =
                {
                    Authorization = HttpRequestMessageUtils.GetAuthorization()
                },
                Content = new StringContent(JsonConvert.SerializeObject(new CreateAccountCommand
                {
                    Balance           = 3,
                    UserId            = _userId,
                    BankAccountNumber = "DE89370400440532013000"
                }), Encoding.UTF8, "application/json")
            };

            // act
            var result = await createAccountFunction.Run(createAccountRequest, mock.Object, CancellationToken.None);

            // assert
            Assert.Multiple(() =>
            {
                Assert.IsInstanceOf <OkObjectResult>(result);
                Assert.AreEqual(1, ((OkObjectResult)result).Value);
            });
        }
示例#2
0
        public async Task CloseAccounts_Run_Success()
        {
            // arrange
            var mock               = new Mock <ILogger>();
            var closeAccount       = new CloseAccounts(_mediatorService);
            var httpRequestMessage = HttpRequestMessageUtils.GetHttpRequestMessage();

            // act
            var result = await closeAccount.Run(httpRequestMessage, mock.Object, CancellationToken.None);

            // assert
            Assert.Multiple(() => { Assert.IsInstanceOf <OkResult>(result); });
        }
        public async Task TestCopyAsync()
        {
            using var client   = new HttpClient();
            client.BaseAddress = new Uri($"https://httpbin.org");
            client.DefaultRequestHeaders.Add("X-Api-Key", "apikey");

            using var req1 = new HttpRequestMessage(HttpMethod.Post, "/post");
            req1.Content   = new StringContent("Hello World!", Encoding.UTF8);

            using (var res1 = await client.SendAsync(req1))
            {
                res1.EnsureSuccessStatusCode();
                Console.WriteLine(await res1.Content.ReadAsStringAsync());
            }

            using var req2 = HttpRequestMessageUtils.Copy(req1);
            using var res2 = await client.SendAsync(req2);

            res2.EnsureSuccessStatusCode();
            Console.WriteLine(await res2.Content.ReadAsStringAsync());
        }
示例#4
0
        public async Task UpdateAccount_Run_Success()
        {
            // arrange
            var mock = new Mock <ILogger>();
            var updateAccountFunction = new UpdateAccount(_mediatorService);
            var updateAccountRequest  = new HttpRequestMessage
            {
                Headers =
                {
                    Authorization = HttpRequestMessageUtils.GetAuthorization()
                },
                Content = new StringContent(JsonConvert.SerializeObject(new UpdateAccountCommand
                {
                    BankAccountNumber = "CH9300762011623852957"
                }), Encoding.UTF8, "application/json")
            };

            // act
            var result = await updateAccountFunction.Run(updateAccountRequest, mock.Object, CancellationToken.None);

            // assert
            Assert.Multiple(() => { Assert.IsInstanceOf <OkResult>(result); });
        }
示例#5
0
        public async Task GetAccounts_Run_Success()
        {
            // arrange
            var mock       = new Mock <ILogger>();
            var getAccount = new GetAccount(_mediatorService);

            // act
            var result = await getAccount.Run(HttpRequestMessageUtils.GetHttpRequestMessage(), mock.Object,
                                              CancellationToken.None);

            // assert
            Assert.Multiple(() =>
            {
                Assert.IsInstanceOf <OkObjectResult>(result);
                var okObjectResult = (OkObjectResult)result;
                var account        = (Account)okObjectResult.Value;
                Assert.IsNotNull(account);
                Assert.AreEqual("CH9300762011623852957", account.BankAccountNumber);
                Assert.AreEqual(3.0M, account.Balance);
                Assert.AreEqual(true, account.Closed);
                Assert.AreEqual(_userId, account.UserId);
            });
        }
示例#6
0
        public async Task CreateAccount_Run_FailValidations()
        {
            // arrange
            var mock = new Mock <ILogger>();
            var createAccountFunction = new CreateAccount(_mediatorService);
            var createAccountRequest  = new HttpRequestMessage
            {
                Headers =
                {
                    Authorization = HttpRequestMessageUtils.GetAuthorization()
                },
                Content = new StringContent(JsonConvert.SerializeObject(new CreateAccountCommand
                {
                    Balance           = 3,
                    BankAccountNumber = "123445544"
                }), Encoding.UTF8, "application/json")
            };

            // act
            var result = await createAccountFunction.Run(createAccountRequest, mock.Object, CancellationToken.None);

            // assert
            Assert.Multiple(() => { Assert.IsInstanceOf <BadRequestObjectResult>(result); });
        }