public void TotalShouldReturnCorrectCount()
        {
            // Arrange
            var first = new GiftSet {
                Id = 1, Name = "First"
            };
            var second = new GiftSet {
                Id = 2, Name = "Second"
            };
            var third = new GiftSet {
                Id = 3, Name = "Third"
            };

            this.db.AddRange(first, second, third);
            this.db.SaveChanges();

            var giftSetService = new AdminGiftSetService(this.db);

            // Act
            var result = giftSetService.Total();

            // Assert
            result
            .Should()
            .Equals(3);
        }
예제 #2
0
        public void SearchShouldReturnCorrectResultsWithFilterAndOrder()
        {
            // Arrange
            var firstGiftSet = new GiftSet {
                Id = 1, Name = "First"
            };
            var secondGiftSet = new GiftSet {
                Id = 2, Name = "Second"
            };
            var thirdGiftSet = new GiftSet {
                Id = 3, Name = "Third"
            };

            this.db.AddRange(firstGiftSet, secondGiftSet, thirdGiftSet);
            this.db.SaveChanges();

            var giftSetService = new ShoppingGiftSetService(this.db);

            // Act
            var result       = giftSetService.Search("d");
            var secondResult = giftSetService.Search(string.Empty);

            // Assert
            result.Should()
            .Match(r =>
                   r.ElementAt(0).Id == 3 &&
                   r.ElementAt(1).Id == 2)
            .And
            .HaveCount(2);

            secondResult
            .Should()
            .HaveCount(3);
        }
예제 #3
0
        public int Create(string name, string description, int quantity, decimal price)
        {
            var giftSet = new GiftSet
            {
                Name        = name,
                Description = description,
                Quantity    = quantity,
                Price       = price
            };

            this.db.GiftSets.Add(giftSet);
            this.db.SaveChanges();

            return(giftSet.Id);
        }
예제 #4
0
        public void ExistsShouldReturnTrueIfItemExist()
        {
            //Arrange
            var firstGiftSet = new GiftSet {
                Id = 1, Name = "First"
            };

            this.db.Add(firstGiftSet);
            this.db.SaveChanges();

            var giftSetService = new ShoppingGiftSetService(this.db);
            //Act
            var result = giftSetService.Exists(1);

            //Assert
            result
            .Should()
            .BeTrue();
        }
        public void EditShouldReturnTrueIfItIsSuccessfull()
        {
            // Arrange
            var giftSet = new GiftSet
            {
                Id   = 1,
                Name = "Test"
            };

            this.db.GiftSets.Add(giftSet);
            this.db.SaveChanges();

            var giftSetService = new AdminGiftSetService(this.db);

            // Act
            var result = giftSetService.Edit(1, "", "", 1, 2);

            // Assert
            result
            .Should()
            .BeTrue();
        }
예제 #6
0
        public void ByIdsShouldReturnCorrectIdsWithCorrectQuantity()
        {
            // Arrange
            var firstGiftSet = new GiftSet {
                Id = 1, Name = "First"
            };
            var secondGiftSet = new GiftSet {
                Id = 2, Name = "Second"
            };
            var thirdGiftSet = new GiftSet {
                Id = 3, Name = "Third"
            };

            this.db.AddRange(firstGiftSet, secondGiftSet, thirdGiftSet);
            this.db.SaveChanges();

            var giftSetService = new ShoppingGiftSetService(this.db);

            IDictionary <int, int> idsWithQuantity = new Dictionary <int, int>()
            {
                { 1, 3 },
                { 2, 3 }
            };

            // Act
            var result = giftSetService.ByIds(idsWithQuantity);

            // Assert
            result
            .Should()
            .Match(r =>
                   (r.ElementAt(0).Id == 1 && r.ElementAt(0).Quantity == 3) &&
                   (r.ElementAt(1).Id == 2 && r.ElementAt(1).Quantity == 3))
            .And
            .HaveCount(2);
        }