Beispiel #1
0
        public async void Get_Items_Returns_Not_Empty_Collection()
        {
            // arrange
            var repository = new Mock <IItemRepository>();

            repository
            .Setup(repo => repo.GetItemsAsync(It.IsAny <GetItemsRequest>()))
            .Returns(Task.FromResult(
                         new GetItemsResponse(true,
                                              new List <IItem>
            {
                new Item
                {
                    ItemId   = Guid.NewGuid(),
                    Title    = "Test",
                    Value    = 1,
                    MaxValue = 1
                }
            })));

            var useCase    = new GetItemsUseCase(repository.Object);
            var outputPort = new GetItemsPresenter();
            var controller = new ItemController(useCase, outputPort);
            var definition = new { Items = new List <Item>(), Success = true }; //to avoid interface deserialization and saving type

            // act
            var resultJson = await controller.GetItems(null, 1, 1);

            // assert
            var result = JsonConvert.DeserializeAnonymousType(((ContentResult)resultJson).Content, definition);

            Assert.True(result.Items.Count == 1);
        }
        public void Returns_Not_Null_Result()
        {
            // arrange
            var presenter  = new GetItemsPresenter();
            var definition = new { Items = new List <Item>(), Success = true }; //to avoid interface deserialization and saving type

            // act
            presenter.Handle(new GetItemsResponse(true, new List <IItem> {
                new Item {
                    ItemId = Guid.NewGuid(), Title = "", Value = 1, MaxValue = 1
                }
            }));

            // assert
            var result = JsonConvert.DeserializeAnonymousType(presenter.ContentResult.Content, definition);

            Assert.True(result.Items.Count == 1);
        }
Beispiel #3
0
 public ItemController(IGetItemsUseCase getItemsUseCase, GetItemsPresenter getItemsPresenter)
 {
     _getItemsUseCase   = getItemsUseCase;
     _getItemsPresenter = getItemsPresenter;
 }