Exemplo n.º 1
0
        public async Task CreateAsync_PhoneNumberValidationFailed_ThrowsError()
        {
            // Arrange
            var fixture  = new Fixture();
            var Person   = new PersonUpdateModel();
            var expected = fixture.Create <string>();

            var PhoneNumberGetService = new Mock <IPhoneNumberGetService>();

            PhoneNumberGetService
            .Setup(x => x.ValidateAsync(Person))
            .Throws(new InvalidOperationException(expected));

            var PersonDataAccess = new Mock <IPersonDataAccess>();

            var PersonGetService = new PersonCreateService(PersonDataAccess.Object, PhoneNumberGetService.Object);

            // Act
            var action = new Func <Task>(() => PersonGetService.CreateAsync(Person));

            // Assert
            await action.Should().ThrowAsync <InvalidOperationException>().WithMessage(expected);

            PersonDataAccess.Verify(x => x.InsertAsync(Person), Times.Never);
        }
Exemplo n.º 2
0
        public async Task CreateAsync_PhoneNumberValidationSucceed_CreatesPerson()
        {
            // Arrange
            var Person   = new PersonUpdateModel();
            var expected = new Person();

            var PhoneNumberGetService = new Mock <IPhoneNumberGetService>();

            PhoneNumberGetService.Setup(x => x.ValidateAsync(Person));

            var PersonDataAccess = new Mock <IPersonDataAccess>();

            PersonDataAccess.Setup(x => x.InsertAsync(Person)).ReturnsAsync(expected);

            var PersonGetService = new PersonCreateService(PersonDataAccess.Object, PhoneNumberGetService.Object);

            // Act
            var result = await PersonGetService.CreateAsync(Person);

            // Assert
            result.Should().Be(expected);
        }
Exemplo n.º 3
0
        public async Task CreateAsync_PersonValidationSucceed_CreatesEmployee()
        {
            // Arrange
            var person   = new PersonUpdateModel();
            var expected = new Person();

            var secretGetService = new Mock <ISecretGetService>();

            secretGetService.Setup(x => x.ValidateAsync(person));

            var personDataAccess = new Mock <IPersonDataAccess>();

            personDataAccess.Setup(x => x.InsertAsync(person)).ReturnsAsync(expected);

            var personGetService = new PersonCreateService(personDataAccess.Object, secretGetService.Object);

            // Act
            var result = await personGetService.CreateAsync(person);

            // Assert
            result.Should().Be(expected);
        }