Beispiel #1
0
        public void GetAsync_GetFromCache_Test()
        {
            // Arrange
            var  now        = DateTime.Now;
            long orderId    = 0;
            long customerId = 0;
            var  customer   = _dataFixture.GetCustomer();
            var  feedback   = _dataFixture.GetFeedback(now, FeedbackType.Order);
            var  order      = _dataFixture.GetOrder(now);

            order.FeedbackSid = feedback.Sid;
            var cachedFeedbackList = new List <Feedback> {
                feedback
            };

            _dataFixture.GetMocks <Feedback>(out var mockRepository, out var mockCacheManager, out var mockOptions);
            _dataFixture.GetMocks(out var orderFacadeMock, out var customerFacadeMock, out var productFacadeMock);

            mockCacheManager
            .Setup(cache => cache.GetFromCacheAsync <List <Feedback> >(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(cachedFeedbackList);

            mockRepository.Setup(repo => repo.GetManagerInstance <OrderFeedbackManager>()).Returns(() => new OrderFeedbackManager());

            customerFacadeMock
            .Setup(facade => facade.GetCustommerByIdAsync(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(customer);

            orderFacadeMock
            .Setup(facade => facade.GetOrderByIdAsync(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(order);

            var orderFeedbackFacade = new OrderFeedbackFacade
                                          (mockRepository.Object,
                                          orderFacadeMock.Object,
                                          customerFacadeMock.Object,
                                          productFacadeMock.Object,
                                          mockCacheManager.Object,
                                          mockOptions.Object);

            // Act
            var result = orderFeedbackFacade.GetAsync(customerId, orderId, CancellationToken.None).Result;

            // Assert
            Assert.NotNull(result);
            Assert.Equal(0, result.Sid);
            Assert.Equal(1, result.FeedbackType);
            Assert.Equal(0, result.CustomerSid);
            Assert.Equal("This is a comment", result.Comment);
        }
Beispiel #2
0
        public void GetAsync_OrderHasNotBeenRated_Test()
        {
            // Arrange
            var  now                = DateTime.Now;
            long orderId            = 0;
            long customerId         = 0;
            var  customer           = _dataFixture.GetCustomer();
            var  order              = _dataFixture.GetOrder(now);
            var  cachedFeedbackList = new List <Feedback> {
            };

            _dataFixture.GetMocks <Feedback>(out var mockRepository, out var mockCacheManager, out var mockOptions);
            _dataFixture.GetMocks(out var orderFacadeMock, out var customerFacadeMock, out var productFacadeMock);

            mockCacheManager
            .Setup(cache => cache.GetFromCacheAsync <List <Feedback> >(It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(cachedFeedbackList);

            mockRepository.Setup(repo => repo.GetManagerInstance <OrderFeedbackManager>()).Returns(() => new OrderFeedbackManager());

            customerFacadeMock
            .Setup(facade => facade.GetCustommerByIdAsync(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(customer);

            orderFacadeMock
            .Setup(facade => facade.GetOrderByIdAsync(It.IsAny <long>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(order);

            var orderFeedbackFacade = new OrderFeedbackFacade
                                          (mockRepository.Object,
                                          orderFacadeMock.Object,
                                          customerFacadeMock.Object,
                                          productFacadeMock.Object,
                                          mockCacheManager.Object,
                                          mockOptions.Object);

            // Act & Assert
            var ex = Assert.Throws <AggregateException>(() => orderFeedbackFacade.GetAsync(customerId, orderId, CancellationToken.None).Result);

            Assert.Equal("One or more errors occurred. (Order with Id 0 has not been rated. There is no feedback to retrieve.)", ex.Message);
        }