public void ClearCallsObjectStorageDelete()
        {
            // Arrange
            var objectStorage = new ObjectStorageBuilder()
                                .SetupDelete()
                                .Build();

            var sut = new RecentProductsService(objectStorage);

            // Act
            sut.Clear().Wait();

            // Assert
            objectStorage.AsMock().Verify();
        }
        private void TestAddProduct(List <Product> currentProducts, Product productToAdd, List <Product> expectedProducts)
        {
            // Arrange
            var objectStorage = new ObjectStorageBuilder()
                                .SetupRead(currentProducts)
                                .SetupWrite(expectedProducts)
                                .Build();

            var sut = new RecentProductsService(objectStorage);

            // Act
            sut.AddProduct(productToAdd).Wait();

            // Assert
            objectStorage.AsMock().Verify();
        }
        public void GetProductWhenStorageThrowsExceptionStoresAndReturnsEmptyCollection()
        {
            // Arrange
            var objectStorage = new ObjectStorageBuilder()
                                .SetupReadThrowsFileNotFoundException()
                                .SetupWrite(new List <Product>())
                                .Build();

            var sut = new RecentProductsService(objectStorage);

            // Act
            var result = sut.GetProducts().Result;

            // Assert
            objectStorage.AsMock().Verify();

            CollectionAssert.AreEqual(
                new List <Product>(),
                result.ToList());
        }
        public void GetProductReadsProductsFromStorage()
        {
            // Arrange
            var products = Enumerable.Range(0, 4)
                           .Select(_ => new ProductBuilder().Build())
                           .ToList();
            var objectStorage = new ObjectStorageBuilder()
                                .SetupRead(products)
                                .Build();

            var sut = new RecentProductsService(objectStorage);

            // Act
            var result = sut.GetProducts().Result;

            // Assert
            objectStorage.AsMock().Verify();

            CollectionAssert.AreEqual(
                products.Select(p => p.Id).ToList(),
                result.Select(p => p.Id).ToList());
        }