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(); }
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); }
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); }
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(); }
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>())); }
public void CreateAsync_NullRequest_Throws() { var service = new CreateOrganisationService(Mock.Of <IOrganisationRepository>(), Mock.Of <IOrganisationValidator>()); Assert.ThrowsAsync <ArgumentNullException>(async() => await service.CreateAsync(null)); }