public async Task GivenTenancyAgreementRef_WhenCreateAgreementsWithCorrectParameters_ShouldNotBeNull()
        {
            //Arrange
            var fakeArrearsAgreementService = new Mock <IArrearsAgreementServiceChannel>();

            fakeArrearsAgreementService.Setup(s => s.CreateArrearsAgreementAsync(It.IsAny <ArrearsAgreementRequest>()))
            .ReturnsAsync(new ArrearsAgreementResponse());

            var fakeCredentialsService = new Mock <ICredentialsService>();
            var serviceRequestBuilder  = new ArrearsServiceRequestBuilder(fakeCredentialsService.Object);

            IArrearsAgreementGateway classUnderTest = new ArrearsAgreementGateway(fakeArrearsAgreementService.Object, serviceRequestBuilder);

            var request = new ArrearsAgreementRequest
            {
                Agreement = new ArrearsAgreementInfo
                {
                    TenancyAgreementRef = "000017/01",
                    Comment             = "Testing",
                },
            };

            //act
            var response = await classUnderTest.CreateArrearsAgreementAsync(request, CancellationToken.None).ConfigureAwait(false);

            //assert
            response.Should().NotBeNull();
        }
示例#2
0
        public ArrearsServiceRequestBuilderTests()
        {
            //pre-arrange
            var credentialsService = new Mock <ICredentialsService>();

            _builder = new ArrearsServiceRequestBuilder(credentialsService.Object);
        }
        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 void GivenTenancyAgreementRef_WhenCreateArrearsAgreementWithNull_ShouldThrowAnException()
        {
            //Arrange
            var fakeArrearsAgreementService = new Mock <IArrearsAgreementServiceChannel>();

            var fakeCredentialsService = new Mock <ICredentialsService>();
            var serviceRequestBuilder  = new ArrearsServiceRequestBuilder(fakeCredentialsService.Object);

            IArrearsAgreementGateway classUnderTest = new ArrearsAgreementGateway(fakeArrearsAgreementService.Object, serviceRequestBuilder);

            //act
            //assert
            Assert.Throws <AggregateException>(() => classUnderTest.CreateArrearsAgreementAsync(null, CancellationToken.None).Result);
        }
示例#5
0
        public CreateArrearsActionDiaryUseCaseTests()
        {
            _fakeGateway = new Mock <IArrearsActionDiaryGateway>();
            var credentialsService = new Mock <ICredentialsService>();

            credentialsService.Setup(s => s.GetUhSourceSystem()).Returns("TestSystem");
            credentialsService.Setup(s => s.GetUhUserCredentials()).Returns(new UserCredential
            {
                UserName     = "******",
                UserPassword = "******",
            });
            IArrearsServiceRequestBuilder requestBuilder = new ArrearsServiceRequestBuilder(credentialsService.Object);

            _classUnderTest = new CreateArrearsActionDiaryUseCase(_fakeGateway.Object, requestBuilder);
        }
        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 GivenTenancyAgreementRef_WhenCreateAgreementsWithCorrectParameters_ShouldReturnAValidObject(
            string tenancyRef, string comment, decimal startBalance, string startDate, string agreementStatusCode,
            bool isBreached, int firstCheck, string firstCheckFrequencyTypeCode, int nextCheck, string nextCheckFrequencyTypeCode,
            string fcaDate, string monitorBalanceCode, decimal amount, string arrearsFrequencyCode,
            string payementInfoStartDate, string payemntInfoComments)
        {
            //Arrange
            var fakeArrearsAgreementService = new Mock <IArrearsAgreementServiceChannel>();

            fakeArrearsAgreementService.Setup(s => s.CreateArrearsAgreementAsync(It.IsAny <ArrearsAgreementRequest>()))
            .ReturnsAsync(new ArrearsAgreementResponse());

            var fakeCredentialsService = new Mock <ICredentialsService>();
            var serviceRequestBuilder  = new ArrearsServiceRequestBuilder(fakeCredentialsService.Object);

            IArrearsAgreementGateway classUnderTest = new ArrearsAgreementGateway(fakeArrearsAgreementService.Object, serviceRequestBuilder);

            var request = new ArrearsAgreementRequest
            {
                Agreement = new ArrearsAgreementInfo
                {
                    TenancyAgreementRef         = tenancyRef,
                    Comment                     = comment,
                    ArrearsAgreementStatusCode  = agreementStatusCode,
                    FcaDate                     = DateTime.Parse(fcaDate),
                    FirstCheck                  = firstCheck,
                    FirstCheckFrequencyTypeCode = firstCheckFrequencyTypeCode,
                    IsBreached                  = isBreached,
                    MonitorBalanceCode          = monitorBalanceCode,
                    NextCheck                   = nextCheck,
                    NextCheckFrequencyTypeCode  = nextCheckFrequencyTypeCode,
                    StartBalance                = startBalance,
                    StartDate                   = DateTime.Parse(startDate)
                },
                PaymentSchedule = new List <ArrearsScheduledPaymentInfo>
                {
                    new ArrearsScheduledPaymentInfo
                    {
                        Amount = amount,
                        ArrearsFrequencyCode = arrearsFrequencyCode,
                        Comments             = payemntInfoComments,
                        StartDate            = DateTime.Parse(payementInfoStartDate)
                    }
                }.ToArray()
            };

            fakeArrearsAgreementService.Setup(s => s.CreateArrearsAgreementAsync(It.IsAny <ArrearsAgreementRequest>()))
            .ReturnsAsync(new ArrearsAgreementResponse
            {
                Success   = true,
                Agreement = new ArrearsAgreementDto
                {
                    TenancyAgreementRef         = tenancyRef,
                    Comment                     = comment,
                    ArrearsAgreementStatusCode  = agreementStatusCode,
                    FcaDate                     = DateTime.Parse(fcaDate),
                    FirstCheck                  = firstCheck,
                    FirstCheckFrequencyTypeCode = firstCheckFrequencyTypeCode,
                    IsBreached                  = isBreached,
                    MonitorBalanceCode          = monitorBalanceCode,
                    NextCheck                   = nextCheck,
                    NextCheckFrequencyTypeCode  = nextCheckFrequencyTypeCode,
                    StartBalance                = startBalance,
                    StartDate                   = DateTime.Parse(startDate),

                    PaymentSchedule = new List <ArrearsScheduledPaymentDto>
                    {
                        new ArrearsScheduledPaymentDto
                        {
                            Amount = amount,
                            ArrearsFrequencyCode = arrearsFrequencyCode,
                            Comments             = payemntInfoComments,
                            StartDate            = DateTime.Parse(payementInfoStartDate)
                        }
                    }.ToArray()
                },
            });

            //act
            var response = await classUnderTest.CreateArrearsAgreementAsync(request, CancellationToken.None).ConfigureAwait(false);

            //assert
            response.Result.Agreement.TenancyAgreementRef.Should().Be(tenancyRef);
            response.Result.Agreement.Comment.Should().Be(comment);
            response.Result.Agreement.ArrearsAgreementStatusCode.Should().Be(agreementStatusCode);
            response.Result.Agreement.FcaDate.Should().Be(DateTime.Parse(fcaDate));
            response.Result.Agreement.FirstCheck.Should().Be(firstCheck);
            response.Result.Agreement.FirstCheckFrequencyTypeCode.Should().Be(firstCheckFrequencyTypeCode);
            response.Result.Agreement.IsBreached.Should().Be(isBreached);
            response.Result.Agreement.MonitorBalanceCode.Should().Be(monitorBalanceCode);
            response.Result.Agreement.NextCheck.Should().Be(nextCheck);
            response.Result.Agreement.NextCheckFrequencyTypeCode.Should().Be(nextCheckFrequencyTypeCode);
            response.Result.Agreement.StartBalance.Should().Be(startBalance);
            response.Result.Agreement.StartDate.Should().Be(DateTime.Parse(startDate));

            response.Result.Agreement.PaymentSchedule.Should().NotBeNull();
            var paymentSchedule = response.Result.Agreement.PaymentSchedule[0];

            paymentSchedule.Amount.Should().Be(amount);
            paymentSchedule.ArrearsFrequencyCode.Should().Be(arrearsFrequencyCode);
            paymentSchedule.Comments.Should().Be(payemntInfoComments);
            paymentSchedule.StartDate.Should().Be(DateTime.Parse(payementInfoStartDate));
        }
        public async Task GivenValidInput_ThenRequestBuilder_AddsCredentials_ToRequest(
            string tenancyRef, string comment, decimal startBalance, string startDate, string agreementStatusCode,
            bool isBreached, int firstCheck, string firstCheckFrequencyTypeCode, int nextCheck, string nextCheckFrequencyTypeCode,
            string fcaDate, string monitorBalanceCode, decimal amount, string arrearsFrequencyCode,
            string payementInfoStartDate, string payemntInfoComments)
        {
            //Arrange
            var fakeArrearsAgreementService = new Mock <IArrearsAgreementServiceChannel>();

            fakeArrearsAgreementService.Setup(s => s.CreateArrearsAgreementAsync(It.IsAny <ArrearsAgreementRequest>()))
            .ReturnsAsync(new ArrearsAgreementResponse());

            var fakeCredentialsService = new Mock <ICredentialsService>();

            fakeCredentialsService.Setup(s => s.GetUhSourceSystem()).Returns("testSourceSystem");
            fakeCredentialsService.Setup(s => s.GetUhUserCredentials()).Returns(new UserCredential
            {
                UserName     = "******",
                UserPassword = "******",
            });
            var serviceRequestBuilder = new ArrearsServiceRequestBuilder(fakeCredentialsService.Object);

            IArrearsAgreementGateway gateway = new ArrearsAgreementGateway(fakeArrearsAgreementService.Object, serviceRequestBuilder);
            var classUnderTest = new CreateArrearsAgreementUseCase(gateway);

            var request = new CreateArrearsAgreementRequest
            {
                AgreementInfo = new ArrearsAgreementInfo
                {
                    TenancyAgreementRef         = tenancyRef,
                    Comment                     = comment,
                    ArrearsAgreementStatusCode  = agreementStatusCode,
                    FcaDate                     = DateTime.Parse(fcaDate),
                    FirstCheck                  = firstCheck,
                    FirstCheckFrequencyTypeCode = firstCheckFrequencyTypeCode,
                    IsBreached                  = isBreached,
                    MonitorBalanceCode          = monitorBalanceCode,
                    NextCheck                   = nextCheck,
                    NextCheckFrequencyTypeCode  = nextCheckFrequencyTypeCode,
                    StartBalance                = startBalance,
                    StartDate                   = DateTime.Parse(startDate)
                },
                PaymentSchedule = new List <ArrearsScheduledPaymentInfo>
                {
                    new ArrearsScheduledPaymentInfo
                    {
                        Amount = amount,
                        ArrearsFrequencyCode = arrearsFrequencyCode,
                        Comments             = payemntInfoComments,
                        StartDate            = DateTime.Parse(payementInfoStartDate)
                    }
                }.ToArray()
            };

            fakeArrearsAgreementService.Setup(s => s.CreateArrearsAgreementAsync(It.IsAny <ArrearsAgreementRequest>()))
            .ReturnsAsync(new ArrearsAgreementResponse
            {
                Success   = true,
                Agreement = new ArrearsAgreementDto
                {
                    TenancyAgreementRef         = tenancyRef,
                    Comment                     = comment,
                    ArrearsAgreementStatusCode  = agreementStatusCode,
                    FcaDate                     = DateTime.Parse(fcaDate),
                    FirstCheck                  = firstCheck,
                    FirstCheckFrequencyTypeCode = firstCheckFrequencyTypeCode,
                    IsBreached                  = isBreached,
                    MonitorBalanceCode          = monitorBalanceCode,
                    NextCheck                   = nextCheck,
                    NextCheckFrequencyTypeCode  = nextCheckFrequencyTypeCode,
                    StartBalance                = startBalance,
                    StartDate                   = DateTime.Parse(startDate),

                    PaymentSchedule = new List <ArrearsScheduledPaymentDto>
                    {
                        new ArrearsScheduledPaymentDto
                        {
                            Amount = amount,
                            ArrearsFrequencyCode = arrearsFrequencyCode,
                            Comments             = payemntInfoComments,
                            StartDate            = DateTime.Parse(payementInfoStartDate)
                        }
                    }.ToArray()
                },
            });
            //act
            await classUnderTest.ExecuteAsync(request, CancellationToken.None);

            //assert
            fakeArrearsAgreementService.Verify(v => v.CreateArrearsAgreementAsync(It.Is <ArrearsAgreementRequest>(i => i.DirectUser != null && !string.IsNullOrEmpty(i.SourceSystem))));
        }
        public async Task GivenInValidInput_ThenUseCase_ShouldReturnInValidResponse(
            string tenancyRef, string comment, decimal startBalance, string startDate, string agreementStatusCode,
            bool isBreached, int firstCheck, string firstCheckFrequencyTypeCode, int nextCheck, string nextCheckFrequencyTypeCode,
            string fcaDate, string monitorBalanceCode, decimal amount, string arrearsFrequencyCode,
            string payementInfoStartDate, string payemntInfoComments)
        {
            //Arrange
            var fakeArrearsAgreementService = new Mock <IArrearsAgreementServiceChannel>();

            fakeArrearsAgreementService.Setup(s => s.CreateArrearsAgreementAsync(It.IsAny <ArrearsAgreementRequest>()))
            .ReturnsAsync(new ArrearsAgreementResponse
            {
                Success      = false,
                ErrorCode    = 1,
                ErrorMessage = "Not enough field",
                Agreement    = new ArrearsAgreementDto
                {
                    TenancyAgreementRef = tenancyRef,
                    Comment             = comment,
                },
            });

            var fakeCredentialsService = new Mock <ICredentialsService>();

            fakeCredentialsService.Setup(s => s.GetUhSourceSystem()).Returns("testSourceSystem");
            fakeCredentialsService.Setup(s => s.GetUhUserCredentials()).Returns(new UserCredential
            {
                UserName     = "******",
                UserPassword = "******",
            });
            var serviceRequestBuilder = new ArrearsServiceRequestBuilder(fakeCredentialsService.Object);

            IArrearsAgreementGateway gateway = new ArrearsAgreementGateway(fakeArrearsAgreementService.Object, serviceRequestBuilder);
            var classUnderTest = new CreateArrearsAgreementUseCase(gateway);

            var request = new CreateArrearsAgreementRequest
            {
                AgreementInfo = new ArrearsAgreementInfo
                {
                    TenancyAgreementRef         = tenancyRef,
                    Comment                     = comment,
                    ArrearsAgreementStatusCode  = agreementStatusCode,
                    FcaDate                     = DateTime.Parse(fcaDate),
                    FirstCheck                  = firstCheck,
                    FirstCheckFrequencyTypeCode = firstCheckFrequencyTypeCode,
                    IsBreached                  = isBreached,
                    MonitorBalanceCode          = monitorBalanceCode,
                    NextCheck                   = nextCheck,
                    NextCheckFrequencyTypeCode  = nextCheckFrequencyTypeCode,
                    StartBalance                = startBalance,
                    StartDate                   = DateTime.Parse(startDate)
                },
                PaymentSchedule = new List <ArrearsScheduledPaymentInfo>
                {
                    new ArrearsScheduledPaymentInfo
                    {
                        Amount = amount,
                        ArrearsFrequencyCode = arrearsFrequencyCode,
                        Comments             = payemntInfoComments,
                        StartDate            = DateTime.Parse(payementInfoStartDate)
                    }
                }.ToArray()
            };


            //act
            var response = await classUnderTest.ExecuteAsync(request, CancellationToken.None);

            //assert
            response.IsSuccess.Should().BeFalse();
            response.Result.Should().BeNull();
            response.Error.Errors.Should().NotBeNullOrEmpty();
            response.Error.Errors[0].Code.Should().Be("UH_1");
            response.Error.Errors[0].Message.Should().Be("Not enough field");
        }