public async void TestGetNoteByLabel() { // Arrange Mock <IKeepService> mockRepo = new Mock <IKeepService>(); MockDB mockDbHelper = new MockDB(); mockRepo.Setup(service => service.GetByLabel("label 1 in second NOte")).Returns(mockDbHelper.GetTestResultListAsync()); NotesController controller = new NotesController(mockRepo.Object); // Act var result = await controller.GetByLabel("label 1 in second NOte"); OkObjectResult objectResult = result as OkObjectResult; Note objectResultValue = objectResult.Value as Note; // Assert Assert.Equal(200, objectResult.StatusCode); // var _controller = GetController(); // var result = await _controller.GetNoteByLabel("label 1 in second NOte"); // var objectresult = result as OkObjectResult; // var notes = objectresult.Value as List<Note>; // //foreach (var x in notes) // //{ // // Assert.Equal("label 1 in second NOte", ); // //} // Assert.Equal(2, notes.Count); }
public async void TestGetAllNotes() { // Arrange Mock <IKeepService> mockRepo = new Mock <IKeepService>(); MockDB mockDbHelper = new MockDB(); mockRepo.Setup(service => service.GetAllNotes()).Returns(mockDbHelper.GetTestResultListAsync()); NotesController controller = new NotesController(mockRepo.Object); // Act var result = await controller.Get(); OkObjectResult objectResult = result as OkObjectResult; List <Note> objectResultValue = objectResult.Value as List <Note>; // Assert Assert.Equal(200, objectResult.StatusCode); //Assert.Equal(1, objectResultValue.ID); //var _controller = GetController(); //var result = await _controller.GetNote(); //var objectresult = result as OkObjectResult; //var notes = objectresult.Value as List<Note>; //Assert.Equal(2, notes.Count()); }
public async void TestDeleteNoteById() { // Arrange Mock <IKeepService> mockRepo = new Mock <IKeepService>(); MockDB mockDbHelper = new MockDB(); mockRepo.Setup(service => service.DeleteNote(1)).Returns(mockDbHelper.GetTestResultData()); NotesController controller = new NotesController(mockRepo.Object); // Act var result = await controller.Delete(1); OkObjectResult objectResult = result as OkObjectResult; Note objectResultValue = objectResult.Value as Note; // Assert Assert.Equal(200, objectResult.StatusCode); // var _controller = GetController(); // var result = _controller.Delete(1); // Assert.True(result.IsCompletedSuccessfully); // //result.StatusCode.Should().Be(System.Net.HttpStatusCode.BadRequest); }