public void GetItemById() { GetReady(); var response = controller.Get(1).ExecuteAsync(CancellationToken.None).Result; Assert.IsNotNull(response.Content); }
public void Get_WhenCalled_ReturnsOkResult() { // Act var result = _controller.Get(); // Assert result.Should().BeOfType <OkObjectResult>(); }
public void GetAllItems() { TestHelper.InitDatabase(); GetReady(); var response = controller.Get().ExecuteAsync(CancellationToken.None).Result; Assert.IsNotNull(response.Content); }
public async Task Get_ReturnsIEnumberableOfItemViewModels() { // Act var result = await itemsController.Get(); // Assert Assert.IsInstanceOfType(GetObjectResultValue(result), typeof(IEnumerable <ItemViewModel>)); }
public async Task Items() { var controller = new ItemsController(); var list = await controller.Get(); Assert.IsTrue(list.Count > 0); }
public async Task GetIdReturnsNotFoundWhenItemDoesNotExist() { var controller = new ItemsController(GetInMemoryContext()); var result = await controller.Get(1); Assert.IsInstanceOf <NotFoundObjectResult>(result); }
public async Task GetReturnsOkWithItems() { var controller = new ItemsController(GetInMemoryContext()); var result = await controller.Get(); Assert.IsInstanceOf <OkObjectResult>(result); }
public void Get_WhenCalled_ShouldReturnAllItems() { // Arrange var user = _context.Users.First(); _controller.MockCurrentUser(user.Id, user.UserName); var item = new Item { Id = 5, Sku = "SKU 5", Name = "Product 5", Description = "Desciption for Product 5", Price = 100, Quantity = 497 }; _context.Items.Add(item); _context.SaveChanges(); // Act var result = _controller.Get(); // Assert (result as OkNegotiatedContentResult <ICollection <ItemDto> >).Content.Should().HaveCount(5); }
public async Task Get_Item_By_Id_Returns_Ok() { //Arrange //Act int listsCount = _itemRepository.Count(); var iactionResult = await _itemsController.Get(_list.Id); var objectResponse = iactionResult as ObjectResult; var resultObject = objectResponse.Value as TodoItem; //Assert Assert.Equal(resultObject.Id, _item.Id); Assert.IsType <OkObjectResult>(iactionResult); Assert.Equal(200, objectResponse.StatusCode); }
public async Task Get_ShouldReturnItems() { var expectedGuid = Guid.NewGuid(); var mediatr = new Mock <IMediator>(); mediatr .Setup(m => m.Send(It.IsAny <IRequest <IList <Item> > >(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult((new List <Item>() { new Item(), new Item() }) as IList <Item>)); var itemController = new ItemsController(mediatr.Object); var actionResults = await itemController.Get(Guid.NewGuid()); var okResult = actionResults as OkObjectResult; Assert.NotNull(okResult); var items = okResult.Value as IList <Item>; Assert.NotNull(items); Assert.Equal(2, items.Count); }
public async Task Create_Item_Via_Controller() { await WithinTestContext(async (ctx) => { var controller = new ItemsController(ctx.ItemsRepository); var itemsInDb = await controller.Get(); itemsInDb.Should().HaveCount(0); await controller.Post(new MyItem { Description = "Test1" }); itemsInDb = await controller.Get(); itemsInDb.Should().HaveCount(1); }); }
public void TestMethod1() { //act List <Item> liste = new List <Item>(cntr.Get()); //assert Assert.AreEqual(5, liste.Count); }
public void Get_Instant_ReturnInternalServerError_When_Repository_Null() { var controller = new ItemsController(null, _protector); var actionResult = controller.Get(); Assert.IsNotNull(actionResult); var result = actionResult as StatusCodeResult; Assert.AreEqual((int)HttpStatusCode.InternalServerError, result.StatusCode); }
public async Task GetIdReturnsOkWhenItemExists() { var context = GetInMemoryContext(true); var controller = new ItemsController(context); var first = context.Items.FirstOrDefault(); var result = await controller.Get(first.ID); Assert.IsInstanceOf <OkObjectResult>(result); context.Dispose(); }
public async void WhenGetByIdIsCalledUnderlyingServiceIsCalled() { var item = new Item {Id = 1, Name = "Filip"}; var service = new Mock<IItemService>(); service.Setup(x => x.GetById(1)).Returns(Task.FromResult(item)); var controller = new ItemsController(service.Object); var result = await controller.Get(1); Assert.Equal(item, result); }
public void GetItems_ReturnsCorrectNumber() { var repo = new MockItemRepository(); var controller = new ItemsController(repo); var data = controller.Get() as OkNegotiatedContentResult <List <IItem> >; Assert.IsNotNull(data); Assert.IsNotNull(data.Content); Assert.IsTrue(data.Content.Count == 4); }
public void GetAll_Returns200OK_WhenDBIsEmpty() { //Arrange mockRepo.Setup(repo => repo.GetAll()).Returns(GetItems(0)); var controller = new ItemsController(mockRepo.Object); //Act var result = controller.Get(); //Assert Assert.IsType <OkObjectResult>(result); }
public void Can_get_item() { using (var context = new ItemsContext(ContextOptions)) { var controller = new ItemsController(context); var item = controller.Get("ItemTwo"); Assert.Equal("ItemTwo", item.Name); } }
public void Get_Instant_ReturnInternalServerError_When_Protector_Null() { _mockProductRepository.Setup(mr => mr.GetAll()).Returns(DataItems.Data); var controller = new ItemsController(_mockProductRepository.Object, null); var actionResult = controller.Get(); Assert.IsNotNull(actionResult); var result = actionResult as StatusCodeResult; Assert.AreEqual((int)HttpStatusCode.InternalServerError, result.StatusCode); }
public void Get_ReturnsAnItem() { var expectedItemCode = "Arduino"; var expectedBasket = new Basket(Guid.NewGuid()); basketsRepositoryMock.Setup(x => x.GetBasket(expectedBasket.Id)) .Returns(expectedBasket); basketsRepositoryMock.Setup(x => x.GetItem(expectedBasket.Id, expectedItemCode)) .Returns(new Item { code = expectedItemCode }); var actual = sut.Get(expectedBasket.Id, expectedItemCode); Assert.IsType <OkObjectResult>(actual); var actualResult = actual as OkObjectResult; Assert.IsType <Item>(actualResult.Value); Assert.Equal(expectedItemCode, (actualResult.Value as Item).code); }
public void WhenIdCalledByGetByIdIsNotFound404IsThrown() { var service = new Mock <IItemService>(); service.Setup(x => x.GetById(1)).Returns(Task.FromResult <Item>(null)); var controller = new ItemsController(service.Object); var ex = AssertEx.TaskThrows <HttpResponseException>(async() => await controller.Get(1)); Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode); }
public void ItemsWithoutParameterReturnBadRequest() { var itemServiceMock = new Mock <IItemService>(); var controller = new ItemsController(itemServiceMock.Object, new ItemSetToYouTubeItemsApiModel()); var actionResult = controller.Get(); var result = actionResult as BadRequestErrorMessageResult; Assert.That(result, Is.Not.Null); Assert.That(result.Message, Is.EqualTo("Items must be called with a Filter parameter")); }
public void GetTest() { //arrange // i before each test //act List <Item> liste = new List <Item>(cntr.Get()); //assert Assert.AreEqual(5, liste.Count); }
public async Task ItemsWithNullFilterReturnsException() { var itemServiceMock = new Mock <IItemService>(); var controller = new ItemsController(itemServiceMock.Object, new ItemSetToYouTubeItemsApiModel()); var actionResult = await controller.Get(null); var result = actionResult as BadRequestErrorMessageResult; Assert.That(result, Is.Not.Null); Assert.That(result.Message, Is.EqualTo("Filter parameter must not be null or empty")); }
public void Can_get_items() { using var context = new ItemsContext(this.ContextOptions); var controller = new ItemsController(context); var items = controller.Get().ToList(); Assert.Equal(3, items.Count); Assert.Equal("ItemOne", items[0].Name); Assert.Equal("ItemThree", items[1].Name); Assert.Equal("ItemTwo", items[2].Name); }
public async Task GET_Items_For_Station() { var controller = new ItemsController(Context); ConfigureRequest(controller); var station = new Station { Id = Guid.NewGuid(), Name = "Station", Region = new Region() { Id = Guid.NewGuid(), Name = "Region" } }; var item = new Item { ItemId = Guid.NewGuid(), Meter = "meter", Name = "test", Station = station, Specification = new Specification { ComparisonTypeName = ComparisonType.Between, LowerBoundValue = "0", UpperBoundValue = "10", Unit = new UnitOfMeasure { Id = Guid.NewGuid(), Name = "C", Abbreviation = "ABB" } } }; Context.Stations.Add(station); Context.ComparisonTypes.Add(new ComparisonType { Name = ComparisonType.Between }); Context.Items.Add(item); Context.SaveChanges(); var result = await GetData <List <ItemModel> >(controller.Get(station.Id, true)); Assert.AreEqual(item.ItemId, result[0].Id); Assert.AreEqual(item.Name, result[0].Name); Assert.AreEqual(item.StationId, result[0].StationId); Assert.AreEqual(Context.Items.Count(), result.Count()); }
public void GetAll_ReturnsOneItem_WhenDBHasOneResource() { //Arrange mockRepo.Setup(repo => repo.GetAll()).Returns(GetItems(1)); var controller = new ItemsController(mockRepo.Object); //Act var result = controller.Get(); //Assert var okResult = result as OkObjectResult; var items = okResult.Value as List <Item>; Assert.Single(items); }
public async void WhenGetByIdIsCalledUnderlyingServiceIsCalled() { var item = new Item { Id = 1, Name = "Filip" }; var service = new Mock <IItemService>(); service.Setup(x => x.GetById(1)).Returns(Task.FromResult(item)); var controller = new ItemsController(service.Object); var result = await controller.Get(1); Assert.Equal(item, result); }
public async Task ItemsWithPageTokenPassesToService() { var itemServiceMock = new Mock <IItemService>(); var filter = "Some values for this Items"; var pageToken = "Atoken"; itemServiceMock.Setup(x => x.GetItems(filter, pageToken)).ReturnsAsync(new ItemSet()); var controller = new ItemsController(itemServiceMock.Object, new ItemSetToYouTubeItemsApiModel()); await controller.Get(filter, pageToken); itemServiceMock.VerifyAll(); }
public void TestGetMethod() { // Arrange // i BeforeEachTest // Act List <Item> Ilist = new List <Item>(cntr.Get()); // Assert Assert.AreEqual(4, Ilist.Count); }
public void GetItems_WorksWithEmptyInventory() { var repo = new MockItemRepository(); repo.Clear(); var controller = new ItemsController(repo); var data = controller.Get() as OkNegotiatedContentResult <List <IItem> >; Assert.IsNotNull(data); Assert.IsNotNull(data.Content); Assert.IsTrue(data.Content.Count == 0); }
public void WhenIdCalledByGetByIdIsNotFound404IsThrown() { var service = new Mock<IItemService>(); service.Setup(x => x.GetById(1)).Returns(Task.FromResult<Item>(null)); var controller = new ItemsController(service.Object); var ex = AssertEx.TaskThrows<HttpResponseException>(async () => await controller.Get(1)); Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode); }