public async void ItemsController_GetSelectedItemDataAsync() { context = GetInMemoryContext(); controller = new ItemsController(context); Item newItem = new Item() { Id = 1, Title = "First", About = "About", CurrentPrice = 222.22m, Image = "image/href" }; await context.AddAsync(newItem); await context.SaveChangesAsync(); OkObjectResult itemRes = await controller.Details(newItem.Id) as OkObjectResult; Assert.NotNull(itemRes); Item item = itemRes.Value as Item; Assert.Equal(newItem.Title, item.Title); Assert.Equal(newItem.Image, item.Image); Assert.Equal(newItem.About, item.About); Assert.Equal(newItem.CurrentPrice, item.CurrentPrice); Assert.Equal(newItem.PriceHistory.Count, item.PriceHistory.Count); }
public async void ItemsController_ThrowNotFoundExceptionItemNullIdAsync() { context = GetInMemoryContext(); controller = new ItemsController(context); Item newItem = new Item() { Id = 1, Title = "First", About = "About", CurrentPrice = 222.22m, Image = "image/href" }; await context.AddAsync(newItem); await context.SaveChangesAsync(); NotFoundResult itemRes = await controller.Details(null) as NotFoundResult; Assert.NotNull(itemRes); }
public async void ItemsController_GetNotEmptyDataAsync() { context = GetInMemoryContext(); controller = new ItemsController(context); Item newItem = new Item() { Id = 1, Title = "First", About = "About", CurrentPrice = 222.22m, Image = "image/href" }; await context.AddAsync(newItem); await context.SaveChangesAsync(); var items = await controller.Index(); Assert.NotEmpty(items); }