示例#1
0
        public async Task ValidateAsync_DoctorExists_DoesNothing()
        {
            // Arrange
            var doctorContainer = new Mock <IDealerContainer>();

            var doctor         = new Dealer();
            var doctorDAL      = new Mock <IDealerDAL>();
            var doctorIdentity = new Mock <IDealerIdentity>();

            doctorDAL.Setup(x => x.GetAsync(doctorIdentity.Object)).ReturnsAsync(doctor);

            var doctorGetService = new DealerService(doctorDAL.Object);

            // Act
            var action = new Func <Task>(() => doctorGetService.ValidateAsync(doctorContainer.Object));

            // Assert
            await action.Should().NotThrowAsync <Exception>();
        }
示例#2
0
        public async Task ValidateAsync_DoctorNotExists_ThrowsError()
        {
            // Arrange
            var fixture = new Fixture();
            var id      = fixture.Create <int>();

            var doctorContainer = new Mock <IDealerContainer>();

            doctorContainer.Setup(x => x.DealerId).Returns(id);
            var doctorIdentity = new Mock <IDealerIdentity>();
            var doctor         = new Dealer();
            var doctorDAL      = new Mock <IDealerDAL>();

            doctorDAL.Setup(x => x.GetAsync(doctorIdentity.Object)).ReturnsAsync((Dealer)null);

            var doctorGetService = new DealerService(doctorDAL.Object);

            // Act
            var action = new Func <Task>(() => doctorGetService.ValidateAsync(doctorContainer.Object));
            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>($"Dealer not found by id {id}");
        }