public void TestChoreMapping() { //create test user User testUser = new User { Id = 22, UserName = "******", FirstName = "John", LastName = "Smith", }; //example chore Chore myChore = new Chore { Id = 1, Title = "dishes", Description = "do the dishes", AssignedUser = testUser, DueDate = new DateTime(2020, 04, 04), Completed = false, Recurring = true, }; //Object->DTO Test ChoreDTO myDTO = new ChoreDTO(myChore); Assert.AreEqual(myDTO.Id, myChore.Id); Assert.AreEqual(myDTO.Title, myChore.Title); Assert.AreEqual(myDTO.Description, myChore.Description); Assert.AreEqual(myDTO.Assignee, myChore.AssignedUser.Id); Assert.AreEqual(myDTO.DueDate, myChore.DueDate); Assert.AreEqual(myDTO.Completed, myChore.Completed); Assert.AreEqual(myDTO.Recurring, myChore.Recurring); var mapper = _mapperHelper.GetMapper(); //DTO->Object Test Chore backToChore = mapper.Map <ChoreDTO, Chore>(myDTO); //in the controller, you would write here "User user = await _userRepository.Get(userId);" //but since we don't have that here, we'll assume it we have the user object backToChore.AssignedUser = testUser; Assert.AreEqual(myDTO.Id, backToChore.Id); Assert.AreEqual(myDTO.Title, backToChore.Title); Assert.AreEqual(myDTO.Description, backToChore.Description); Assert.AreEqual(myDTO.Assignee, backToChore.AssignedUser.Id); Assert.AreEqual(myDTO.DueDate, backToChore.DueDate); Assert.AreEqual(myDTO.Completed, backToChore.Completed); Assert.AreEqual(myDTO.Recurring, backToChore.Recurring); }
public async Task TestCreateChoreNonexistentAssignee() { // Arrange var chore = new ChoreDTO { Title = "dishes", Description = "do the dishes", Assignee = 100, DueDate = new DateTime(2020, 04, 04), Completed = false, Recurring = true, }; // Act var response = await _choreController.CreateChoreForFlat(chore); // Assert Assert.IsInstanceOf <BadRequestResult>(response); }
public async Task TestCreateChoreForFlatAsync() { Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); Trace.AutoFlush = true; // Arrange var chore = new ChoreDTO { Title = "lawn", Description = "mow the lawn", Assignee = 1, DueDate = new DateTime(2020, 05, 05), Completed = false, Recurring = true, }; List <Chore> expectedChores = await _choresRepository.GetAll(); expectedChores.Add(new Chore { Id = 3, // this is what we expect based on DevelopmentDatabaseSetup intialisation Title = "lawn", Description = "mow the lawn", AssignedUser = await _userRepository.Get(1), DueDate = new DateTime(2020, 05, 05), Completed = false, Recurring = true, }); // Act var response = await _choreController.CreateChoreForFlat(chore); // Assert OK result and Chore has been added to repository Assert.IsInstanceOf <OkResult>(response); List <Chore> newChores = await _choresRepository.GetAll(); Assert.AreEqual(expectedChores, newChores); }