public async Task EditAsyncShouldEditContact() { var db = DbInfrastructure.GetDatabase(); var contact = new Contact { Title = "Title", Message = "Message", ContactType = ContactType.Bug, IsAnswered = false }; await db.AddAsync(contact); await db.SaveChangesAsync(); var contactAdminService = new ContactAdminService(db); const string Title = "Edited Title"; const string Message = "Edited Message"; await contactAdminService.EditAsync(contact.Id, Title, Message, ContactType.Question, true); var actualContact = await contactAdminService.ByIdAsync(contact.Id); actualContact.Title.Should().Be(Title); actualContact.Message.Should().Be(Message); actualContact.ContactType.Should().Be(ContactType.Question); actualContact.IsAnswered.Should().BeTrue(); }
public async Task ByIdAsyncShouldReturnContactById() { var db = DbInfrastructure.GetDatabase(); const string Title = "Title"; const string Message = "Message"; var contact = new Contact { Title = Title, Message = Message }; await db.AddAsync(contact); await db.SaveChangesAsync(); var contactAdminService = new ContactAdminService(db); var actualContact = await contactAdminService.ByIdAsync(contact.Id); actualContact.Title.Should().Be(Title); actualContact.Message.Should().Be(Message); }
public async Task CountAsyncShoulReturnCorrectCount() { var db = DbInfrastructure.GetDatabase(); await this.Add100AnsweredContacts(db); await this.Add100UnansweredContacts(db); await this.Add100RandomAnsweredContacts(db); var contactAdminService = new ContactAdminService(db); var count = await contactAdminService.CountAsync(); count.Should().Be(300); }
public async Task AllAsyncWithoutFilterShouldReturnAllContactsByPages() { var db = DbInfrastructure.GetDatabase(); await this.Add100RandomAnsweredContacts(db); await db.SaveChangesAsync(); var contactAdminService = new ContactAdminService(db); for (var i = 0; i < 10; i++) { var contacts = await contactAdminService.AllAsync(i + 1, ContactFilter.All); contacts.Should().HaveCount(ContactsPerPage); } }
public async Task DeleteAsyncShouldDeleteContact() { var db = DbInfrastructure.GetDatabase(); var contact = new Contact { Title = "Title", Message = "Message" }; await db.AddAsync(contact); await db.SaveChangesAsync(); var contactAdminService = new ContactAdminService(db); await contactAdminService.DeleteAsync(contact.Id); var count = await contactAdminService.CountAsync(); count.Should().Be(0); }
public async Task AllAsyncShouldReturnCorrectContactsByUnansweredFilter() { var db = DbInfrastructure.GetDatabase(); await this.Add100UnansweredContacts(db); await db.SaveChangesAsync(); var contactAdminService = new ContactAdminService(db); for (var i = 0; i < 10; i++) { var contacts = await contactAdminService.AllAsync(i + 1, ContactFilter.All); contacts.Should().HaveCount(ContactsPerPage); foreach (var contact in contacts) { contact .Should() .Match <ContactServiceModel>(c => c.IsAnswered == false); } } }