コード例 #1
0
        public async Task CreateAsync_CreatesOrganisationWithCorrectValues()
        {
            var expected = OrganisationBuilder.Create(1).WithAddress(AddressBuilder.Create().Build()).Build();

            var calledBack = false;
            var mockOrganisationRepository = new Mock <IOrganisationRepository>();

            mockOrganisationRepository.Setup(r => r.CreateOrganisationAsync(It.IsAny <Organisation>()))
            .Callback((Organisation actual) =>
            {
                actual.Should().BeEquivalentTo(expected, c => c
                                               .Excluding(o => o.OrganisationId)
                                               .Using <DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, 1000))
                                               .WhenTypeIs <DateTime>());
                actual.OrganisationId.Should().NotBeEmpty();
                calledBack = true;
            });

            var service = new CreateOrganisationService(mockOrganisationRepository.Object, SetUpValidator(true));

            await service.CreateAsync(SetUpRequest(
                                          expected.Name,
                                          expected.OdsCode,
                                          expected.PrimaryRoleId,
                                          expected.CatalogueAgreementSigned,
                                          expected.Address));

            calledBack.Should().BeTrue();
        }
コード例 #2
0
 public void Constructor_NullValidator_Throws()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var _ = new CreateOrganisationService(Mock.Of <IOrganisationRepository>(), null);
     });
 }
 public static void Constructor_NullRepository_Throws()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         _ = new CreateOrganisationService(null, Mock.Of <IOrganisationValidator>());
     });
 }
コード例 #4
0
        public async Task CreateAsync_OnFailure_Calls_CreateOrganisationAsync_ZeroTimes()
        {
            var mockOrganisationRepository = SetUpRepositoryMock();
            var service = new CreateOrganisationService(mockOrganisationRepository.Object, SetUpValidator(false));

            await service.CreateAsync(SetUpRequest());

            mockOrganisationRepository.Verify(r => r.CreateOrganisationAsync(It.IsAny <Organisation>()), Times.Never);
        }
コード例 #5
0
        public async Task CreateAsync_OnSuccess_Calls_CreateOrganisationAsync_Once()
        {
            var mockOrganisationRepository = SetUpRepositoryMock();
            var service = new CreateOrganisationService(mockOrganisationRepository.Object, SetUpValidator(true));

            await service.CreateAsync(SetUpRequest());

            mockOrganisationRepository.Verify(r => r.CreateOrganisationAsync(It.IsAny <Organisation>()), Times.Once);
        }
コード例 #6
0
        public async Task CreateAsync_ValidationSuccess_Returns_Success()
        {
            var service = new CreateOrganisationService(SetUpRepository(), SetUpValidator(true));

            var result = await service.CreateAsync(SetUpRequest());

            result.IsSuccess.Should().BeTrue();
            result.Value.Should().NotBeEmpty();
        }
コード例 #7
0
        public async Task CreateAsync_ValidationFailure_Returns_Failure()
        {
            var service = new CreateOrganisationService(SetUpRepository(), SetUpValidator(false));

            var result = await service.CreateAsync(SetUpRequest());

            result.IsSuccess.Should().BeFalse();
            result.Value.Should().BeNull();
            result.Should().BeEquivalentTo(Result.Failure <Guid?>(new List <ErrorDetails>()));
        }
コード例 #8
0
        public void CreateAsync_NullRequest_Throws()
        {
            var service = new CreateOrganisationService(Mock.Of <IOrganisationRepository>(), Mock.Of <IOrganisationValidator>());

            Assert.ThrowsAsync <ArgumentNullException>(async() => await service.CreateAsync(null));
        }