public void UnSubscribe_Returns()
        {
            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.UnSubscribe(1, 1)).IgnoreArguments().Returns(
                new OperationStatus()
            {
                Status = true
            }).MustBeCalled();

            //Act
            SubscriberController controller   = new SubscriberController(mockJournalRepository, mockSubscriptionRepository, membershipRepository);
            ActionResult         actionResult = (ActionResult)controller.UnSubscribe(1);

            //Assert
            Assert.IsNotNull(actionResult);
        }
예제 #2
0
        public async void Details_ReturnsNotFound()
        {
            // Arrange
            options = new DbContextOptionsBuilder <VitecContext>()
                      .UseInMemoryDatabase(databaseName: "DetailsNotFoundSubsriberDatabase").Options;
            VitecContext context = new VitecContext(options);

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

            // Act
            IActionResult result = await controller.Details(6);

            Assert.IsType <NotFoundResult>(result);
        }
        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);
        }
예제 #4
0
        private static void StartSubscriberForm(object ipAndPort)
        {
            SubscriberController subscriberController = new SubscriberController((string)ipAndPort);
            SubscriberGUI        subscriberGUI        = new SubscriberGUI(subscriberController);

            subscriberController.setDelegates(subscriberGUI.newPost, subscriberGUI.refreshActiveTopicList, subscriberGUI.deletedTopic);
            Application.Run(subscriberGUI);
        }
        public async Task GetAll_ReturnsNotFound_OnNoItemsExist()
        {
            _fakeSubscriberCollection = null;
            _mockSubscriberService.Setup(a => a.GetAll()).Returns(Task.FromResult(_fakeSubscriberCollection.AsEnumerable()));

            var controller = new SubscriberController(_mockSubscriberService.Object, _logger.Object);
            var result     = await controller.Get();

            Assert.IsInstanceOf <NotFoundResult>(result.Result);
        }
예제 #6
0
        public void Return_Subscriber_DetailModel()
        {
            var mockSubscriberService = new Mock <ISubscriber>();

            mockSubscriberService.Setup(r => r.Get(521)).Returns(GetSubscriber());
            var controller = new SubscriberController(mockSubscriberService.Object);

            var result = controller.Detail(521);

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

            viewResult.Subject.Model.Should().BeOfType <SubscriberDetailModel>();
        }
예제 #7
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 ValidateDates_ForDates_ReturnActionResult(string startDate, string endDate)
        {
            // Arrange
            var controller = new SubscriberController();

            // Act
            var result = controller.ValidateDates(startDate, endDate, true) as JsonResult;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.Data.ShouldNotBeNull());
        }
        public void EditUDF_ForAccessedUser_ReturnActionResult()
        {
            // Arrange
            InitializeUdf();
            var controller = new SubscriberController();

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

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.View.ShouldBeNull(),
                () => result.MasterName.ShouldBe(string.Empty));
        }
        public void LoadUDFHistoryData_ForDataTable_ReturnActionResult()
        {
            // Arrange
            InitializeUdfHistory();
            var controller = new SubscriberController();

            // Act
            var result = controller.LoadUDFHistoryData(GroupId, GroupId, GroupId) as JsonResult;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.Data.ShouldNotBeNull());
        }
        public void ExportData_SubcribeTypeDefault_SearchTypeDefault_DownloadTypeDefault()
        {
            // Arrange
            var controller = new SubscriberController();

            InitilizeExportDataTests();

            // Act
            controller.ExportData(SampleGroupId1, String.Empty, SampleEmail, String.Empty, String.Empty, SampleFilter, SampleFromDate, SampleToDate, true);

            // Assert
            _contentType.ShouldBeEmpty();
            _fileText.ShouldBeEmpty();
        }
        public void LoadAddUDFData_ForAccessedUser_ReturnActionResult()
        {
            // Arrange
            InitializeAddUdf();
            var controller = new SubscriberController();

            // Act
            var result = controller.LoadAddUDFData(GroupId, GroupId) as PartialViewResult;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.ViewName.ShouldBe(PartialModal));
        }
예제 #13
0
        public void Display_Nameless_Subscriber()
        {
            var mockSubscriberService = new Mock <ISubscriber>();

            mockSubscriberService.Setup(r => r.Get(429)).Returns(GetNamelessSubscriber());
            var controller = new SubscriberController(mockSubscriberService.Object);

            var result = controller.Detail(429);


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

            viewResult.Subject.Model.Should().BeOfType <SubscriberDetailModel>();
        }
예제 #14
0
        private SubscriberController ArrangeSubscriberController(UserProfile profile)
        {
            Mapper.CreateMap <JournalViewModel, Journal>();
            Mapper.CreateMap <Journal, JournalViewModel>();

            var repository = JournalMocks.MockJournalRepositoryWithContext();
            var service    = JournalMocks.MockSubscriptionServiceWithContext();
            IStaticMembershipService memServiceMock  = JournalMocks.MockIStaticMembershipService(profile).MockObject;
            ISessionProvider         sessionProvider = JournalMocks.MockISessionProvider(profile).MockObject;
            SubscriberController     controller      = new SubscriberController(repository, service, memServiceMock);

            controller.CheckRequestAuthenticatd = false;
            controller.SetSessionProvider(sessionProvider);
            return(controller);
        }
        public async Task GetAll_ReturnsBadRequest_OnUnhandledException()
        {
            _fakeSubscriberCollection = null;
            _mockSubscriberService.Setup(a => a.GetAll()).Throws(new Exception("An error occurred"));

            var controller   = new SubscriberController(_mockSubscriberService.Object, _logger.Object);
            var actionResult = await controller.Get();

            var badRequestResult = actionResult.Result as BadRequestObjectResult;

            Assert.IsInstanceOf(typeof(BadRequestObjectResult), badRequestResult);
            Assert.IsNotNull(badRequestResult);
            Assert.IsNotNull(badRequestResult.Value);
            Assert.AreEqual((int)HttpStatusCode.BadRequest, badRequestResult.StatusCode);
        }
        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));
        }
        public void SubLogReadToGrid_ForEmail_ReturnActionResult()
        {
            // Arrange
            InitializeLog();
            var controller = new SubscriberController();

            // Act
            var result = controller.SubLogReadToGrid(new DataSourceRequest(), EmailId,
                                                     GroupId, PageNumber, PageSize) as JsonResult;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.Data.ShouldNotBeNull());
        }
        public void ExportData_SubcribeTypeDefault_SearchTypeEquals_DownloadTypeCsv()
        {
            // Arrange
            var controller = new SubscriberController();

            InitilizeExportDataTests();

            // Act
            controller.ExportData(SampleGroupId1, String.Empty, SampleEmail, SearchTypeEquals, DownloadTypeCsv, SampleFilter, SampleFromDate, SampleToDate, true);

            // Assert
            _contentType.ShouldBe("text/csv");
            _fileText.ShouldBe("\"DataColumn1\",\"DataColumn2\",\"Data11\",\"Data12\",\"Data21\",\"Data22\",");
            _responseHeader.ShouldContain("emails.csv");
            _responseText.ShouldContain("emails.csv");
        }
        public void ExportData_SubcribeTypeDefault_SearchTypeStarts_DownloadTypeXml()
        {
            // Arrange
            var controller = new SubscriberController();

            InitilizeExportDataTests();

            // Act
            controller.ExportData(SampleGroupId1, String.Empty, SampleEmail, SearchTypeStarts, DownloadTypeXml, SampleFilter, SampleFromDate, SampleToDate, true);

            // Assert
            _contentType.ShouldBe("text/xml");
            _fileText.ShouldBeEmpty();
            _responseHeader.ShouldContain("emails.xml");
            _responseText.ShouldContain("emails.xml");
        }
        public async Task Post_ReturnsBadRequest_OnUnhandledException()
        {
            _mockSubscriberService.Setup(a => a.Add(It.IsAny <Subscriber>())).ThrowsAsync(new Exception("A service error occurred")).Verifiable();

            var controller = new SubscriberController(_mockSubscriberService.Object, _logger.Object);
            var result     = await controller.Post(_fakeSubscriber);

            var badRequestResult = result as BadRequestResult;

            Assert.IsInstanceOf <ActionResult>(result);
            Assert.IsInstanceOf <BadRequestResult>(badRequestResult);
            _mockSubscriberService.VerifyAll();

            Assert.IsNotNull(badRequestResult);
            Assert.AreEqual((int)HttpStatusCode.BadRequest, badRequestResult.StatusCode);
        }
        public void ExportData_SubcribeTypeAll_SearchTypeLike_DownloadTypeXls()
        {
            // Arrange
            var controller = new SubscriberController();

            InitilizeExportDataTests();

            // Act
            controller.ExportData(SampleGroupId1, SubcribeTypeAll, SampleEmail, SearchTypeLike, DownloadTypeXls, SampleFilter, SampleFromDate, SampleToDate, true);

            // Assert
            _contentType.ShouldBe("application/vnd.ms-excel");
            _fileText.ShouldBe("DataColumn1\tDataColumn2\tData11\tData12\tData21\tData22\t");
            _responseHeader.ShouldContain("emails.xls");
            _responseText.ShouldContain("emails.xls");
        }
        public async Task Post_ReturnsBadRequest_GivenInvalidModel()
        {
            _fakeSubscriber = new Subscriber();

            var controller = new SubscriberController(_mockSubscriberService.Object, _logger.Object);

            controller.ModelState.AddModelError("description", "Description is required");
            var result = await controller.Post(_fakeSubscriber);

            var badRequestResult = result as BadRequestObjectResult;

            Assert.IsInstanceOf <ActionResult>(result);
            Assert.IsInstanceOf(typeof(BadRequestObjectResult), badRequestResult);
            Assert.IsNotNull(badRequestResult);
            Assert.IsNotNull(badRequestResult.Value);
            Assert.AreEqual((int)HttpStatusCode.BadRequest, badRequestResult.StatusCode);
        }
        public async Task Post_ReturnsBadRequest_OnFailedDbInsert()
        {
            _mockSubscriberService.Setup(a => a.Add(It.IsAny <Subscriber>())).Returns(Task.FromResult(new SubscriberResponse("error occurred") as ISubscriberResponse)).Verifiable();

            var controller = new SubscriberController(_mockSubscriberService.Object, _logger.Object);
            var result     = await controller.Post(_fakeSubscriber);

            var badRequestResult = result as BadRequestObjectResult;

            Assert.IsInstanceOf <ActionResult>(result);
            _mockSubscriberService.VerifyAll();

            Assert.IsInstanceOf(typeof(BadRequestObjectResult), badRequestResult);
            Assert.IsNotNull(badRequestResult);
            Assert.IsNotNull(badRequestResult.Value);
            Assert.AreEqual((int)HttpStatusCode.BadRequest, badRequestResult.StatusCode);
        }
        public async Task GetAll_ReturnsOkResult()
        {
            _mockSubscriberService.Setup(a => a.GetAll()).Returns(Task.FromResult(_fakeSubscriberCollection.AsEnumerable()));

            var expectedValue = 1;
            var controller    = new SubscriberController(_mockSubscriberService.Object, _logger.Object);
            var result        = await controller.Get();

            var okResult = result.Result as OkObjectResult;

            Assert.IsInstanceOf <OkObjectResult>(result.Result);
            Assert.IsNotNull(okResult.Value);
            Assert.IsInstanceOf <IEnumerable <Subscriber> >(okResult.Value);
            var returnValue = okResult.Value as IEnumerable <Subscriber>;

            Assert.AreEqual(_fakeSubscriberCollection.Count, returnValue.Count());
            Assert.AreEqual(expectedValue, returnValue.FirstOrDefault().Id);
        }
        public void EmailsSubsReadToGrid_ForInvalidSortDescription_PartialViewResult(string param, bool activity)
        {
            // Arrange
            InitializeEmailSubs();
            var controller = new SubscriberController();
            var request    = new DataSourceRequest()
            {
                Sorts = CreateSortsList()
            };

            // Act
            var result = controller.EmailsSubsReadToGrid(request, GroupId, Like, param,
                                                         ProfileName, FromDate, ToDate, activity, PageNumber, PageSize) as PartialViewResult;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.ViewName.ShouldBe(PartialErrorNotification));
        }
        public async Task Post_ReturnsNewItemRoute()
        {
            _mockSubscriberService.Setup(a => a.Add(It.IsAny <Subscriber>())).Returns(Task.FromResult(new SubscriberResponse(_fakeSubscriber) as ISubscriberResponse)).Verifiable();

            var controller = new SubscriberController(_mockSubscriberService.Object, _logger.Object);
            var result     = await controller.Post(_fakeSubscriber);

            var createdAtActionResult = result as CreatedAtActionResult;

            Assert.IsInstanceOf <ActionResult>(result);
            Assert.IsInstanceOf <CreatedAtActionResult>(createdAtActionResult);
            Assert.AreEqual("Get", createdAtActionResult.ActionName);
            Assert.IsTrue(createdAtActionResult.RouteValues.ContainsKey("id"));
            Assert.AreEqual(createdAtActionResult.RouteValues["id"], _fakeSubscriber.Id);

            var returnValue = createdAtActionResult.Value as Subscriber;

            Assert.AreEqual(_fakeSubscriber.Id, returnValue.Id);
            _mockSubscriberService.VerifyAll();
        }
예제 #27
0
        public void Return_Subscriber_Detail_View()
        {
            var mockSubscriberService = new Mock <ISubscriber>();

            mockSubscriberService.Setup(r => r.Get(429)).Returns(GetSubscriber());
            mockSubscriberService.Setup(r => r.GetRentals(429)).Returns(new List <Rental> {
            });
            mockSubscriberService.Setup(r => r.GetRentalHistories(429)).Returns(new List <RentalHistory> {
            });
            mockSubscriberService.Setup(r => r.GetHolds(429)).Returns(new List <Hold> {
            });
            var controller = new SubscriberController(mockSubscriberService.Object);

            var result = controller.Detail(429);

            var viewResult = result.Should().BeOfType <ViewResult>();
            var viewModel  = viewResult.Subject.ViewData.Model.Should().BeAssignableTo <SubscriberDetailModel>();

            viewModel.Subject.FirstName.Should().Be("Jim");
            viewModel.Subject.LastName.Should().Be("Brown");
        }
        public void Update_ForEmail_ReturnActionResult(bool param)
        {
            // Arrange
            InitializeUpdate(param);
            var controller = new SubscriberController();
            var email      = new CommunicatorModels.Email()
            {
                EmailAddress      = EmailAddress,
                EmailID           = GroupId,
                CurrentGroupID    = GroupId,
                FormatTypeCode    = EmailAddress,
                SubscribeTypeCode = EmailAddress
            };

            // Act
            var result = controller.Update(email) as JsonResult;

            // Assert
            result.ShouldSatisfyAllConditions(
                () => result.ShouldNotBeNull(),
                () => result.Data.ShouldNotBeNull());
        }
예제 #29
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);
        }
예제 #30
0
        public async void Details_ReturnsRequested_Model()
        {
            // Arrange
            options = new DbContextOptionsBuilder <VitecContext>()
                      .UseInMemoryDatabase(databaseName: "DetailsSubsriberDatabase").Options;
            VitecContext context = new VitecContext(options);

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

            // Act
            IActionResult result = await controller.Details(2);

            ViewResult viewResult = Assert.IsType <ViewResult>(result);
            // Assert that it's a subscriber as model
            Subscriber sub = Assert.IsAssignableFrom <Subscriber>(viewResult.ViewData.Model);

            // Assert that it's the correct subsriber
            Assert.Equal("Nidolaj", sub.FirstName);
        }
예제 #31
0
        public void MyTestInitialize()
        {
            var request = new HttpRequest("", "http://example.com/", "");
            var response = new HttpResponse(TextWriter.Null);
            HttpContext.Current = new HttpContext(request, response);
            var sessionStateContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(),
                                            new HttpStaticObjectsCollection(), 10, true,
                                            HttpCookieMode.AutoDetect,
                                            SessionStateMode.InProc, false);
            SessionStateUtility.AddHttpSessionStateToContext(HttpContext.Current, sessionStateContainer);

            _subscriberController = new SubscriberController();
            var httpContext = new HttpContextWrapper(HttpContext.Current);
            _subscriberController.ControllerContext = new ControllerContext(httpContext, new RouteData(), _subscriberController);

            var windowsIdentity = WindowsIdentity.GetCurrent();
            var userName = string.Empty;
            if (windowsIdentity != null)
            {
                userName = windowsIdentity.Name.Split('\\')[1];
            }
            CurrentUser.SetInstance(userName);
            _user = CurrentUser.AsRosettianUser();
        }
예제 #32
0
 public void MyTestInitialize()
 {
     // Set up the SubscriberController
         SubscriberControllerForTests = DependencyResolver.Current.GetService<SubscriberController>();
 }