Ejemplo n.º 1
0
        public async Task Get_OutOfBounds()
        {
            // Arrange
            var id     = 6;
            var client = SetupMock_PurchaseDto(id);
            var config = new Mock <IConfiguration>();

            client.BaseAddress = new Uri("http://localhost:12324/");
            config.SetupGet(s => s["PurchasesUrl"]).Returns("http:localhost:12324/");
            var purchaseRepo = new FakePurchaseRepository(TestData.Purchases().Select(p => new Purchase
            {
                AccountId = p.AccountId,
                Id        = p.Id,
                ProductId = p.ProductId
            }).ToList());
            var service = new PurchaseService(null, config.Object, new NullLogger <PurchaseService>(), purchaseRepo)
            {
                HttpClient = client
            };

            // Act
            var result = await service.GetPurchase(id);

            // Assert
            Assert.IsNull(result);
        }
Ejemplo n.º 2
0
        public async Task GetAll_Success()
        {
            // Arrange
            var client = SetupMock_ListPurchaseDto();
            var config = new Mock <IConfiguration>();

            client.BaseAddress = new Uri("http://localhost:12324/");
            config.SetupGet(s => s["PurchasesUrl"]).Returns("http:localhost:12324/");
            var purchaseRepo = new FakePurchaseRepository(TestData.Purchases().Select(p => new Purchase
            {
                AccountId = p.AccountId,
                Id        = p.Id,
                ProductId = p.ProductId
            }).ToList());
            var service = new PurchaseService(null, config.Object, new NullLogger <PurchaseService>(), purchaseRepo)
            {
                HttpClient = client
            };

            // Act
            var result = await service.GetAll();

            // Assert
            Assert.IsNotNull(result);
            foreach (var purchase in result)
            {
                var testItem = TestData.Purchases().FirstOrDefault(p => p.Id == purchase.PurchaseRef);
                Assert.AreEqual(testItem.Id, purchase.PurchaseRef);
                Assert.AreEqual(testItem.AccountId, purchase.AccountId);
            }
        }