public async void CreateReservation_ContactInvalid_False() { //arrange var contact = ContactFaker.GetContactContactNameGreater(); var contactType = ContactTypeFaker.GetContactTypeOk(); var faker = new Faker(); var message = faker.Lorem.Paragraph(); var createReservationCommand = new CreateReservationCommand( contactId: contact.Id, contactName: contact.Name, contactPhone: contact.Name, contactBirthdate: contact.BirthDate, contactTypeId: contactType.Id, message: message ); _dependencyResolverMock .Setup(x => x.Resolve <IReservationRepository>()) .Returns(_reservationRepositoryMock.Object); _dependencyResolverMock .Setup(x => x.Resolve <IContactRepository>()) .Returns(_contactRepositoryMock.Object); _dependencyResolverMock .Setup(x => x.Resolve <IContactTypeRepository>()) .Returns(_contactTypeRepositoryMock.Object); _contactRepositoryMock.Setup(x => x.GetByIdAsync(createReservationCommand.ContactId.Value)) .Returns(Task.FromResult((Contact)null)); _contactTypeRepositoryMock.Setup(x => x.GetByIdAsync(createReservationCommand.ContactTypeId)) .Returns(Task.FromResult(contactType)); var handler = new ReservationCommandHandler(_dependencyResolverMock.Object); //Act var result = await handler.Handle(createReservationCommand, new CancellationToken()); //Assert Assert.False(result.Success); _contactRepositoryMock.Verify(x => x.GetByIdAsync(createReservationCommand.ContactId.Value), Times.Once); _reservationRepositoryMock.Verify(x => x.AddAsync(It.IsAny <Reservation>()), Times.Never); _reservationRepositoryMock.Verify(x => x.CommitAsync(), Times.Never); }
public void ContactType_Valid() { //arrange var contactType = ContactTypeFaker.GetContactTypeOk(); //act var result = contactType.IsValid(); //assert Assert.True(result); }
public void ContactType_MessageGreaterLessLimite_False() { //arrange var contactType = ContactTypeFaker.GetContactTypeMessageGreaterLessLimite(); //act var result = contactType.IsValid(); //assert Assert.False(result); }
public void ContactType_MessageEmpty_False() { //arrange var contactType = ContactTypeFaker.GetContactTypeMessageEmpty(); //act var result = contactType.IsValid(); //assert Assert.False(result); }
public void Contact_ChangeContactType_Ok() { //arrange var contact = ContactFaker.GetContactOk(); var contactType = ContactTypeFaker.GetContactTypeOk(); //act contact.ChangeContactType(contactType); //assert Assert.True(contact.ContactTypeId == contactType.Id); }
public async Task ContactAddAsyncOk() { var contactType = ContactTypeFaker.GetContactTypeOk(); var count = await _db.ContactTypes.CountAsync(); await _contactTypeRepository.AddAsync(contactType); var rowsAffected = await _contactTypeRepository.CommitAsync(); var contactFromDatabase = await _contactTypeRepository.GetByIdAsync(contactType.Id); Assert.True(rowsAffected.QuantityOfRecordsAffecteds == 1); Assert.NotNull(contactFromDatabase); }
public async Task RemoveOk() { var contactType = ContactTypeFaker.GetContactTypeOk(); await _db.ContactTypes.AddAsync(contactType); await _db.SaveChangesAsync(); _contactTypeRepository.Remove(contactType.Id); await _contactTypeRepository.CommitAsync(); var result = await _contactTypeRepository.GetByIdAsync(contactType.Id); Assert.Null(result); }
public async void EditContact_True() { //arrange var contact = ContactFaker.GetContactOk(); var contactType = ContactTypeFaker.GetContactTypeOk(); var faker = new Faker(); var contactName = faker.Person.FullName; var randomizerTextRegex = RandomizerFactory .GetRandomizer(new FieldOptionsTextRegex { Pattern = @"^\(999\) 999-\d{4}$" }); var contactPhone = randomizerTextRegex.Generate().ToUpper(); var contactBirthDate = faker.Date.Past(); var editContactCommand = new EditContactCommand( contactId: contact.Id, contactName: contactName, contactPhone: contactPhone, contactBirthDate: contactBirthDate, contactTypeId: contactType.Id ); _dependencyResolverMock .Setup(x => x.Resolve <IContactRepository>()) .Returns(_contactRepositoryMock.Object); _dependencyResolverMock .Setup(x => x.Resolve <IContactTypeRepository>()) .Returns(_contactTypeRepositoryMock.Object); _contactRepositoryMock .Setup(x => x.GetByIdAsync(editContactCommand.ContactId)) .Returns(Task.FromResult(contact)); _contactTypeRepositoryMock .Setup(x => x.GetByIdAsync(editContactCommand.ContactTypeId)) .Returns(Task.FromResult(contactType)); _contactRepositoryMock .Setup(x => x.CommitAsync()) .Returns(Task.FromResult(CommitResponse.Ok())); var handler = new ContactCommandHandler(_dependencyResolverMock.Object); //act var result = await handler.Handle(editContactCommand, new CancellationToken()); //result Assert.True(result.Success); _contactRepositoryMock.Verify(x => x.GetByIdAsync(editContactCommand.ContactId), Times.Once); _contactTypeRepositoryMock.Verify(x => x.GetByIdAsync(editContactCommand.ContactTypeId), Times.Once); _contactRepositoryMock.Verify(x => x.Update(contact), Times.Once); _contactRepositoryMock.Verify(x => x.CommitAsync(), Times.Once); _mediatorHandler.Verify(x => x.NotifyDomainNotification(It.IsAny <DomainNotification>()), Times.Never); }