Esempio n. 1
0
        public void CreateBud_CallsRepositoryMethod()
        {
            // Arrange
            var      mockRepo = new Mock <IAuktionRepository>();
            var      service  = new AuktionService(mockRepo.Object, null);
            BudModel obj      = null;
            var      bud      = new BiddingViewModel {
                AuktionID = 1, Summa = 2
            };
            var user = new NauktionUser {
                Id = "abcdef"
            };

            mockRepo.Setup(t => t.CreateBudAsync(It.IsAny <BudModel>()))
            .Callback((BudModel o) => obj = o)
            .Returns(Task.CompletedTask).Verifiable();

            // Act
            service.CreateBudAsync(bud, user).GetAwaiter().GetResult();

            // Assert
            Assert.IsNotNull(obj);
            Assert.AreEqual(1, obj.AuktionID);
            Assert.AreEqual(2, obj.Summa);
            Assert.AreEqual(user.Id, obj.Budgivare);
            mockRepo.Verify();
        }
Esempio n. 2
0
        public void GetAuktion_GoesThroughService()
        {
            // Arrange
            var mockRepo = new Mock <IAuktionRepository>();
            var service  = new AuktionService(mockRepo.Object, null);

            var model = new AuktionModel();

            mockRepo.Setup(t => t.GetAuktionAsync(It.IsAny <int>()))
            .ReturnsAsync(model)
            .Verifiable();

            // Act
            AuktionModel result = service.GetAuktionAsync(1).Result;

            // Assert
            Assert.AreSame(model, result);
            mockRepo.Verify();
        }
Esempio n. 3
0
        public void ListBuds_OrderByBid()
        {
            // Arrange
            var mockRepo = new Mock <IAuktionRepository>();
            var service  = new AuktionService(mockRepo.Object, null);

            List <BudModel> modelList = GetMeSomeBuds(1);
            List <BudModel> expected  = modelList.OrderByDescending(b => b.Summa).ToList();

            mockRepo.Setup(t => t.ListBudsAsync(1))
            .ReturnsAsync(modelList)
            .Verifiable();

            // Act
            List <BudModel> result = service.ListBudsAsync(1).Result;

            // Assert
            mockRepo.Verify();
            CollectionAssert.AreEqual(expected, result);
        }
Esempio n. 4
0
        public void ListAuktions_OrderByDate()
        {
            // Arrange
            var mockRepo = new Mock <IAuktionRepository>();
            var service  = new AuktionService(mockRepo.Object, null);

            List <AuktionModel> modelList = GetMeSomeAuktions();
            List <AuktionModel> expected  = modelList
                                            .OrderByDescending(a => a.StartDatum)
                                            .ToList();

            mockRepo.Setup(t => t.ListAuktionsAsync())
            .ReturnsAsync(modelList)
            .Verifiable();

            // Act
            List <AuktionModel> result = service.ListAuktionsAsync(includeClosed: true).Result;

            // Assert
            mockRepo.Verify();
            CollectionAssert.AreEqual(expected, result);
        }
Esempio n. 5
0
        public void ListAuktions_FilterOutClosed()
        {
            // Arrange
            var mockRepo = new Mock <IAuktionRepository>();
            var service  = new AuktionService(mockRepo.Object, null);

            List <AuktionModel> modelList = GetMeSomeAuktions();
            List <AuktionModel> expected  = modelList
                                            .Where(a => !a.IsClosed())
                                            .ToList();

            mockRepo.Setup(t => t.ListAuktionsAsync())
            .ReturnsAsync(modelList)
            .Verifiable();

            // Act
            List <AuktionModel> result = service.ListAuktionsAsync(includeClosed: false).Result;

            // Assert
            mockRepo.Verify();
            CollectionAssert.AreEquivalent(expected, result);
        }