public async Task GetDataByIdAsync() { //Arrange var data = new List <DefaultModel>() { new DefaultModel { Id = Guid.NewGuid(), Field1 = "default", Field2 = 1, Field3 = "default2", Field4 = 2 }, new DefaultModel { Id = Guid.NewGuid(), Field1 = "default", Field2 = 2, Field3 = "default2", Field4 = 3 } }; var dbSet = NSubstituteUtils.CreateMockDbSet(data); var context = Substitute.For <DefaultContext>(); context.DefaultModels = dbSet; var controller = new DefaultController(context); //Act var result = await controller.GetDataByIdAsync(data[1].Id); //Assert Assert.IsInstanceOf(typeof(OkObjectResult), result); var resultValue = result as OkObjectResult; Assert.AreEqual(data[1], resultValue.Value); }
public async Task GetDataById_NotFoundResultAsync() { //Arrange var data = new List <DefaultModel>() { new DefaultModel { Id = Guid.NewGuid(), Field1 = "default", Field2 = 1, Field3 = "default2", Field4 = 2 }, new DefaultModel { Id = Guid.NewGuid(), Field1 = "default", Field2 = 2, Field3 = "default2", Field4 = 3 } }; var dbSet = NSubstituteUtils.CreateMockDbSet(data); var context = Substitute.For <DefaultContext>(); context.DefaultModels = dbSet; var controller = new DefaultController(context); //Act var result = await controller.GetDataByIdAsync(Guid.Empty); //Assert Assert.IsInstanceOf(typeof(NotFoundResult), result); }