Example #1
0
        public void Validate_NullOrganisation_Throws()
        {
            var mockOrganisationRepository = SetUpGetByOdsCodeAsync(null);

            var validator = new OrganisationValidator(mockOrganisationRepository);

            Assert.ThrowsAsync <ArgumentNullException>(async() => await validator.ValidateAsync(null));
        }
Example #2
0
        public async Task Validate_Organisation_Does_Exist_Returns_Failure()
        {
            var existingOrganisation = OrganisationBuilder.Create(1).Build();

            var mockOrganisationRepository = SetUpGetByOdsCodeAsync(existingOrganisation);

            var validator = new OrganisationValidator(mockOrganisationRepository);

            var expected = Result.Failure(OrganisationErrors.OrganisationAlreadyExists());
            var actual   = await validator.ValidateAsync(existingOrganisation);

            actual.Should().BeEquivalentTo(expected);
        }
Example #3
0
        public async Task Validate_Organisation_Does_Not_Exist_Returns_Success()
        {
            var newOrganisation = OrganisationBuilder.Create(1).Build();

            var mockOrganisationRepository = SetUpGetByOdsCodeAsync(null);

            var validator = new OrganisationValidator(mockOrganisationRepository);

            var expected = Result.Success();
            var actual   = await validator.ValidateAsync(newOrganisation);

            actual.Should().BeEquivalentTo(expected);
        }
Example #4
0
        public async Task Validate_Calls_OrganisationRepository_Once()
        {
            var newOrganisation = OrganisationBuilder.Create(1).Build();

            var mockOrganisationRepository = new Mock <IOrganisationRepository>();

            mockOrganisationRepository.Setup(r => r.GetByOdsCodeAsync(It.IsAny <string>())).ReturnsAsync(newOrganisation);

            var validator = new OrganisationValidator(mockOrganisationRepository.Object);

            await validator.ValidateAsync(newOrganisation);

            mockOrganisationRepository.Verify(r => r.GetByOdsCodeAsync(newOrganisation.OdsCode), Times.Once);
        }