public async Task DeleteUserStock_must_return_Notound_when_count_not_found_userstock_with_provided_id() { var data = new List<UserStock> { new UserStock {ID = 0, Name = "DAX"}, new UserStock {ID = 1, Name = "NYSE"} }.AsQueryable(); var mockSet = new Mock<DbSet<UserStock>>(); mockSet.Setup(m => m.FindAsync(It.IsAny<object[]>())).Returns<object[]>((key) => Task.FromResult(data.SingleOrDefault(us => us.ID == (int)key[0]))); var mockContext = new Mock<IStockExchangeDbContext>(); mockContext.Setup(m => m.UserStocks).Returns(mockSet.Object); var service = new UserStocksController(mockContext.Object); var result = await service.DeleteUserStock(3); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public async Task DeleteUserStock_must_remove_userstock_from_set() { var data = new List<UserStock> { new UserStock {ID = 0, Name = "DAX", User = @"ALIS-PC\Ali"}, new UserStock {ID = 1, Name = "NYSE", User = @"ALIS-PC\Ali"} }.AsQueryable(); var mockSet = new Mock<DbSet<UserStock>>(); mockSet.Setup(m => m.FindAsync(It.IsAny<object[]>())).Returns<object[]>((key) => Task.FromResult(data.SingleOrDefault(us => us.ID == (int)key[0]))); var mockContext = new Mock<IStockExchangeDbContext>(); mockContext.Setup(m => m.UserStocks).Returns(mockSet.Object); var service = new UserStocksController(mockContext.Object); var result = await service.DeleteUserStock(0); Assert.IsInstanceOfType(result, typeof(OkNegotiatedContentResult<UserStock>)); mockSet.Verify(m => m.Remove(It.IsAny<UserStock>()), Times.Once()); mockContext.Verify(m => m.SaveChangesAsync(), Times.Once()); }