public async Task GivenValidedInput_GatewayReceivesCorrectInput()
        {
            //arrange
            var tenancyAgreementRef = "Test";

            _fakeGateway.Setup(s => s.CreateActionDiaryEntryAsync(It.Is <ArrearsActionCreateRequest>(i => i.ArrearsAction.TenancyAgreementRef.Equals("Test"))))
            .ReturnsAsync(new ArrearsActionResponse
            {
                Success       = true,
                ArrearsAction = new ArrearsActionLogDto
                {
                    ActionCategory      = "Test",
                    ActionCode          = "HAC",
                    IsCommentOnly       = true,
                    UserName            = "******",
                    Id                  = 1,
                    TenancyAgreementRef = tenancyAgreementRef
                }
            });
            var request = new ActionDiaryRequest
            {
                ActionCategory      = "Test",
                ActionCode          = "HAC",
                Username            = "******",
                TenancyAgreementRef = tenancyAgreementRef
            };
            //act
            var response = await _classUnderTest.ExecuteAsync(request);

            //assert
            _fakeGateway.Verify(v => v.CreateActionDiaryEntryAsync(It.Is <ArrearsActionCreateRequest>(i => i.ArrearsAction.TenancyAgreementRef.Equals("Test"))));
        }
Beispiel #2
0
        public async Task WhenGivenCorrectParamaters_AndThereIsErrorFromWebService_ApiShouldRespondWith500()
        {
            //Arrange
            var fakeUseCase    = new Mock <ICreateArrearsActionDiaryUseCase>();
            var classUnderTest = new ArrearsActionDiaryController(fakeUseCase.Object);

            fakeUseCase.Setup(a => a.ExecuteAsync(It.IsAny <ActionDiaryRequest>())).ReturnsAsync(new ArrearsActionResponse
            {
                Success = false
            });

            //Act
            ActionDiaryRequest request = new ActionDiaryRequest
            {
                TenancyAgreementRef = "s",
                Comment             = "test",
                Username            = "******",
                ActionCode          = "t1"
            };

            var response = await classUnderTest.Post(request);

            //Assert
            Assert.IsType <ObjectResult>(response);
        }
        public async Task GivenValidInput_ThenRequestBuilder_AddsCredentials_ToRequest()
        {
            //arrange
            var tenancyAgreementRef = "Test";

            _fakeGateway.Setup(s => s.CreateActionDiaryEntryAsync(It.Is <ArrearsActionCreateRequest>(i => i.ArrearsAction.TenancyAgreementRef.Equals("Test"))))
            .ReturnsAsync(new ArrearsActionResponse
            {
                Success       = true,
                ArrearsAction = new ArrearsActionLogDto
                {
                    Id = 1,
                    TenancyAgreementRef = tenancyAgreementRef
                }
            });
            var request = new ActionDiaryRequest
            {
                Username            = "******",
                TenancyAgreementRef = tenancyAgreementRef
            };
            //act
            var response = await _classUnderTest.ExecuteAsync(request);

            //assert
            _fakeGateway.Verify(v => v.CreateActionDiaryEntryAsync(It.Is <ArrearsActionCreateRequest>(i => i.DirectUser != null && !string.IsNullOrEmpty(i.SourceSystem))));
        }
        public void builds_a_valid_request_when_valid_parameters_are_provided(string actionCategory, string actionCode,
                                                                              string username, string comment, string companyCode, string sessionToken, string tenancyAgreementRef)
        {
            var fakeCredentialsService = new Mock <ICredentialsService>();

            fakeCredentialsService.Setup(s => s.GetUhUserCredentials()).Returns(new UserCredential
            {
                UserName     = "******",
                UserPassword = "******"
            });
            fakeCredentialsService.Setup(s => s.GetUhSourceSystem()).Returns("TestSystem");
            var serviceRequestBuilder = new ArrearsServiceRequestBuilder(fakeCredentialsService.Object);
            var serviceRequest        = new ActionDiaryRequest
            {
                ActionCategory      = actionCategory,
                ActionCode          = actionCode,
                Username            = username,
                Comment             = comment,
                CompanyCode         = companyCode,
                SessionToken        = sessionToken,
                TenancyAgreementRef = tenancyAgreementRef
            };
            var request = serviceRequestBuilder.BuildNewActionDiaryRequest(serviceRequest);

            Assert.Equal(actionCategory, request.ArrearsAction.ActionCategory);
            Assert.Equal(actionCode, request.ArrearsAction.ActionCode);
            Assert.Equal(comment, request.ArrearsAction.Comment);
            Assert.Equal(tenancyAgreementRef, request.ArrearsAction.TenancyAgreementRef);
            Assert.Equal("testUser", request.DirectUser.UserName);
            Assert.Equal("testPassword", request.DirectUser.UserPassword);
            Assert.Equal("TestSystem", request.SourceSystem);
            Assert.Equal(sessionToken, request.SessionToken);
            Assert.Equal(companyCode, request.CompanyCode);
            Assert.NotEqual(username, request.DirectUser.UserName);
        }
        public static bool IsValid(this ActionDiaryRequest request)
        {
            var validator = new ActionDiaryRequestValidator();

            if (request?.TenancyAgreementRef == null)
            {
                return(false);
            }
            var result = validator.Validate(request);

            return(result.IsValid);
        }
        public async Task <IActionResult> Post([FromBody][Required] ActionDiaryRequest request)
        {
            if (!request.IsValid())
            {
                return(BadRequest());
            }

            var response = await _createArrearsActionDiaryUseCase.ExecuteAsync(request);

            if (!response.Success)
            {
                return(StatusCode(500, response));
            }
            return(Ok(response));
        }
        public void return_a_built_request_object()
        {
            var fakeCredentialsService = new Mock <ICredentialsService>();
            var serviceRequestBuilder  = new ArrearsServiceRequestBuilder(fakeCredentialsService.Object);
            var serviceRequest         = new ActionDiaryRequest
            {
                ActionCategory      = "test",
                ActionCode          = "test",
                Username            = "******",
                Comment             = "test",
                CompanyCode         = "test",
                SessionToken        = "test",
                TenancyAgreementRef = "test"
            };
            var request = serviceRequestBuilder.BuildNewActionDiaryRequest(serviceRequest);

            Assert.IsType <ArrearsActionCreateRequest>(request);
        }
        public async Task <ArrearsActionResponse> ExecuteAsync(ActionDiaryRequest request)
        {
            Tenancy tenancy = _tenanciesGateway.GetTenancyForRef(request.TenancyAgreementRef);

            var thisRequest = _requestBuilder.BuildNewActionDiaryRequest(request, tenancy.CurrentBalance);

            var response = await _arrearsActionDiaryGateway.CreateActionDiaryEntryAsync(thisRequest);

            if (response.Success)
            {
                if (request.Username != null || request.Username != "")
                {
                    await _arrearsActionDiaryGateway.UpdateRecordingUserName(request.Username,
                                                                             response.ArrearsAction.Id);
                }
                response.ArrearsAction.UserName = request.Username;
            }
            return(response);
        }
        public async Task GivenValidInput_GatewayResponseWith_Success()
        {
            //arrange
            Tenancy tenancy = Fake.GenerateTenancyDetails();

            _stubTenanciesGateway.SetTenancyDetails(tenancy.TenancyRef, tenancy);
            _fakeGateway.Setup(s => s.CreateActionDiaryEntryAsync(It.Is <ArrearsActionCreateRequest>(i =>
                                                                                                     i.ArrearsAction.TenancyAgreementRef.Equals(tenancy.TenancyRef) &&
                                                                                                     i.ArrearsAction.ActionBalance.Equals(tenancy.CurrentBalance)
                                                                                                     )))
            .ReturnsAsync(new ArrearsActionResponse
            {
                Success       = true,
                ArrearsAction = new ArrearsActionLogDto
                {
                    ActionBalance       = tenancy.CurrentBalance,
                    ActionCategory      = "Test",
                    ActionCode          = "HAC",
                    IsCommentOnly       = true,
                    UserName            = "******",
                    Id                  = 1,
                    TenancyAgreementRef = tenancy.TenancyRef
                }
            });
            var request = new ActionDiaryRequest
            {
                ActionCategory      = "Test",
                ActionCode          = "HAC",
                Username            = "******",
                TenancyAgreementRef = tenancy.TenancyRef
            };
            //act
            var response = await _classUnderTest.ExecuteAsync(request);

            //assert
            Assert.Equal(true, response.Success);
            Assert.Equal(tenancy.TenancyRef, response.ArrearsAction.TenancyAgreementRef);
            Assert.Equal(tenancy.CurrentBalance, response.ArrearsAction.ActionBalance);
        }
Beispiel #10
0
        public ArrearsActionCreateRequest BuildNewActionDiaryRequest(ActionDiaryRequest request, decimal actionBalance = 0)
        {
            if (request == null)
            {
                throw new ArgumentNullException("ArrearsServiceRequestBuilder-BuildActionDiaryRequest:request is null");
            }
            var newRequest = new ArrearsActionCreateRequest
            {
                ArrearsAction = new ArrearsActionInfo
                {
                    ActionBalance       = actionBalance,
                    ActionCategory      = request.ActionCategory,
                    ActionCode          = request.ActionCode,
                    Comment             = request.Comment,
                    TenancyAgreementRef = request.TenancyAgreementRef
                },
                CompanyCode  = request.CompanyCode,
                DirectUser   = _credentialsService.GetUhUserCredentials(),
                SessionToken = request.SessionToken,
                SourceSystem = _credentialsService.GetUhSourceSystem()
            };

            return(newRequest);
        }
        public async Task GivenInvalidInput_GatewayResponseWith_Failure()
        {
            //arrange
            var tenancyAgreementRef = "InvalidTest";

            _fakeGateway.Setup(s => s.CreateActionDiaryEntryAsync(It.Is <ArrearsActionCreateRequest>(i => i.ArrearsAction.TenancyAgreementRef.Equals(string.Empty))))
            .ReturnsAsync(new ArrearsActionResponse
            {
                Success       = false,
                ArrearsAction = new ArrearsActionLogDto
                {
                    TenancyAgreementRef = string.Empty
                }
            });
            var request = new ActionDiaryRequest
            {
                TenancyAgreementRef = string.Empty
            };
            //act
            var response = await _classUnderTest.ExecuteAsync(request);

            //assert
            Assert.False(response.Success);
        }