public void Index_Returns_All_Journals()
        {
            Mapper.CreateMap <List <Journal>, List <SubscriptionViewModel> >();

            //Arrange
            var membershipRepository = Mock.Create <IStaticMembershipService>();
            var userMock             = Mock.Create <MembershipUser>();

            Mock.Arrange(() => userMock.ProviderUserKey).Returns(1);
            Mock.Arrange(() => membershipRepository.GetUser()).Returns(userMock);

            var mockJournalRepository      = Mock.Create <IJournalRepository>();
            var mockSubscriptionRepository = Mock.Create <ISubscriptionRepository>();

            Mock.Arrange(() => mockSubscriptionRepository.GetAllJournals()).IgnoreArguments().Returns(new List <Journal>()
            {
                new Journal {
                    Id = 1, Description = "TestDesc", FileName = "TestFilename.pdf", Title = "Tester", UserId = 1, ModifiedDate = DateTime.Now
                },
                new Journal {
                    Id = 1, Description = "TestDesc2", FileName = "TestFilename2.pdf", Title = "Tester2", UserId = 1, ModifiedDate = DateTime.Now
                }
            }).MustBeCalled();

            //Act
            SubscriberController controller   = new SubscriberController(mockJournalRepository, mockSubscriptionRepository, membershipRepository);
            ViewResult           actionResult = (ViewResult)controller.Index();

            //Assert
            Assert.IsNotNull(actionResult);
        }
コード例 #2
0
        public void Return_SubscriberIndexModel()
        {
            var mockSubscriberService = new Mock <ISubscriber>();

            mockSubscriberService.Setup(r => r.GetAll()).Returns(GetAllSubscribers());
            var controller = new SubscriberController(mockSubscriberService.Object);

            var result = controller.Index("");

            var viewResult = result.Should().BeOfType <ViewResult>();

            viewResult.Subject.Model.Should().BeOfType <SubscriberIndexModel>();
        }
        public void Index_ForGroupNotNull_ReturnActionResult(string comparator, bool param)
        {
            // Arrange
            var controller = new SubscriberController();

            InitializeIndex(param);

            // Act
            var result = controller.Index(GroupId, comparator) as ViewResult;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.View.ShouldBeNull(),
                () => result.MasterName.ShouldBe(string.Empty));
        }
コード例 #4
0
        public async void Index_ReturnsAViewResult_WithListOfSubscribers()
        {
            // Arrange
            options = new DbContextOptionsBuilder <VitecContext>()
                      .UseInMemoryDatabase(databaseName: "IndexSubsriberDatabase").Options;
            VitecContext context = new VitecContext(options);

            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Kenni",
                LastName    = "Bobber",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**"
            });
            context.Subscriber.Add(new Subscriber
            {
                FirstName   = "Nidolaj",
                LastName    = "Molle",
                PhoneNumber = "88888888",
                Active      = true,
                Email       = "*****@*****.**"
            });
            context.SaveChanges();

            SubscriberController controller = new SubscriberController(context);

            // Act
            IActionResult result = await controller.Index();

            // Assert that it's a viewResult
            ViewResult viewResult = Assert.IsType <ViewResult>(result);
            // Assert that the model returned is a list of subscribers
            List <Subscriber> model = Assert.IsAssignableFrom <List <Subscriber> >(viewResult.ViewData.Model);

            // Asser that there's 2 subscribers
            Assert.Equal(2, model.Count);
        }
コード例 #5
0
        public void Index_Returns_Journals_Flag_Set4_Subscribed()
        {
            //Arrange
            var profile = new UserProfile {
                UserId = 6
            };;
            SubscriberController controller = this.ArrangeSubscriberController(profile);

            //Act
            var actionResult = controller.Index();

            //Assert
            Assert.IsInstanceOfType(actionResult, typeof(ViewResult));
            var model = ((ViewResult)actionResult).Model as IEnumerable <UserJournal>;

            //moto to verify the flag is set correct only for the subscribed journals
            var subscribed = model.Where(m => m.IsSubscribed).Select(s => s.Id);

            if (subscribed != null && subscribed.Count() > 0)
            {
                var usersSubscribed = JournalMocks.SubscriptionData.Where(s => subscribed.Contains(s.JournalId)).Select(u => u.UserId);
                Assert.IsTrue(usersSubscribed.Contains(profile.UserId));
            }
        }