public static void Register_ActivateAccount(Guid UserNameValidActivationToken)
 {
     ControllerFake<UserAccountController, object> controller = new ControllerFake<UserAccountController, object>();
     ActionResult resultValid = controller.Controller.Activate(UserNameValidActivationToken.ToString());
     Assert.AreEqual(true, resultValid.GetType() == typeof(RedirectResult));
     Assert.AreEqual(true, (((RedirectResult)resultValid).Url == controller.Controller.RedirectResultOnLogIn().Url));
 }
 public static void ResetPassword_Succeed(string UserEmailValid, Guid CantAccessMyAccountToken, string NewPassword)
 {
     ControllerFake<UserAccountController, ResetPasswordClientModel> controller = new ControllerFake<UserAccountController, ResetPasswordClientModel>();
     ResetPasswordClientModel model = new ResetPasswordClientModel() { NewPassword = NewPassword, ConfirmPassword = NewPassword };
     ActionResult actionResult = controller.Controller.ResetPassword(CantAccessMyAccountToken.ToString(), model);
     Assert.AreEqual(true, actionResult.GetType() == typeof(RedirectResult));
     Assert.AreEqual(true, (((RedirectResult)actionResult).Url == controller.Controller.RedirectResultOnLogIn().Url));
 }
 public static void Login_Succeed(string UserEmailValid, string UserPassword)
 {
     ControllerFake<UserAccountController, LogOnViewModel> controller = new ControllerFake<UserAccountController, LogOnViewModel>();
     LogOnViewModel logOnModel = new LogOnViewModel();
     logOnModel.Email = UserEmailValid;
     logOnModel.Password = UserPassword;
     ActionResult resultPost = controller.Controller.LogOn(logOnModel);
     Assert.AreEqual(true, HttpContext.Current.Response.Cookies[UserRequestModel_Keys.WcfFormsAuthenticationCookieName].Value != string.Empty);
     Assert.AreEqual(true, resultPost.GetType() == typeof(RedirectResult));
     Assert.AreEqual(true, (((RedirectResult)resultPost).Url == controller.Controller.RedirectResultOnLogIn().Url));
 }
 public static void Register_Succeed(string UserEmailValid, string UserPassword, ref Guid UserNameValidActivationToken)
 {
     ControllerFake<UserAccountController, RegisterViewModel> controller = new ControllerFake<UserAccountController, RegisterViewModel>();
     Mock<RegisterViewModel> model = new Mock<RegisterViewModel>();
     model.Object.Email = UserEmailValid;
     model.Object.Password = UserPassword;
     ActionResult resultValid = controller.Controller.Register(model.Object);
     bool validFound = ((RegisterViewModel)((ViewResult)resultValid).Model).Result.CreateStatus == MembershipCreateStatus.Success;
     Assert.AreEqual(true, validFound);
     UserNameValidActivationToken = ((RegisterViewModel)((ViewResult)resultValid).Model).Result.ActivateUserToken;
 }
        public static void CantAccessMyAccount_Succeed(string UserEmailValid, ref Guid CantAccessMyAccountToken)
        {
            ControllerFake<UserAccountController, CantAccessYourAccountViewModel> controller = new ControllerFake<UserAccountController, CantAccessYourAccountViewModel>();
            ActionResult resultInvalid = controller.Controller.CantAccessYourAccount(new CantAccessYourAccountViewModel()
            {
                EmailAddress = UserEmailValid
            });
            Assert.AreEqual(true, ((CantAccessYourAccountViewModel)((ViewResult)resultInvalid).Model).Result.IsValid == true);
            Assert.AreEqual(true, ((CantAccessYourAccountViewModel)((ViewResult)resultInvalid).Model).Result.Data.User.Email == UserEmailValid);

            CantAccessMyAccountToken = ((CantAccessYourAccountViewModel)((ViewResult)resultInvalid).Model).Result.Data.ChangePasswordToken;
        }
Esempio n. 6
0
        public void ReturnForbidWhenDeleteOtherNews()
        {
            // Assign
            var news            = GetFakeNews().First();
            var dateTimeFactory = new DateTimeFactory();

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory);

                // Act
                var result = newsController.Delete(1);

                // Assert
                Assert.IsType <ForbidResult>(result);
            }
        }
        public async Task Delete_Faq_Should_Return_OkResult()
        {
            // Assign
            var faq = new Faq
            {
                Id       = 1,
                Question = "",
                Answer   = "",
                Category = new Category
                {
                    Title = "",
                },
                FaqTags = new List <FaqTag>
                {
                    new FaqTag
                    {
                        Tag = new Tag
                        {
                            Id = 1,
                        },
                    },
                },
            };

            DbContextFake.SeedDb <IntranetApiContext>(c => c.Add(faq));

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var faqController = ControllerFake.GetController <FaqsController>(context);

                // Act
                var result = await faqController.DeleteConfirmed(1);

                // Assert
                Assert.True(result.ValidateActionRedirect("Index"));
            }
            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                Assert.Equal(0, context.Faqs.Count());
                Assert.Equal(0, context.Categories.Count());
                Assert.Equal(0, context.Tags.Count());
            }
        }
        public async Task Get_All_Should_Return_Empty_List()
        {
            // Assign
            var fileServiceMock = new Mock <IFileStorageService>();

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var policyController = ControllerFake.GetController <PoliciesController>(context, fileServiceMock.Object);

                // Act
                var response = await policyController.Index();

                var result = response.GetModelAs <IEnumerable <Category> >();

                // Assert
                Assert.IsType <ViewResult>(response);
                Assert.Equal(0, result.Count());
            }
        }
        public async Task ReturnInvalidModelStateWhenDeleteOtherNews()
        {
            // Assign
            var news            = GetFakeNews().First();
            var dateTimeFactory = new DateTimeFactory();
            var fileServiceMock = new Mock <IFileStorageService>();

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory, fileServiceMock.Object);

                // Act
                var result = await newsController.DeleteConfirmed(1);

                // Assert
                Assert.False(result.ModelStateIsValid());
            }
        }
Esempio n. 10
0
        public void ReturnNotFoundWhenUpdate()
        {
            // Assign
            var news            = GetFakeNews();
            int id              = 5;
            var dateTimeFactory = new DateTimeFactory();

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory);

                // Act
                var result = newsController.Put(id, new NewsViewModel(news.First()));

                // Assert
                Assert.IsType <NotFoundObjectResult>(result);
            }
        }
Esempio n. 11
0
        public void ReturnOkResultWhenPosting()
        {
            // Assign
            var newsItem        = GetFakeNews().First();
            var newsItemVM      = new NewsViewModel(newsItem);
            var username        = "******";
            var user            = new ClaimsPrincipalFake(new Claim("username", username));
            var dateTimeFactory = new DateTimeFactory();

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory);
                newsController.ControllerContext.HttpContext.User = user;

                // Act
                var result = newsController.Post(newsItemVM);

                // Assert
                Assert.IsType <OkObjectResult>(result);
            }
        }
Esempio n. 12
0
        public void ReturnOkResultWhenDeleteAsAdmin()
        {
            // Assign
            var news            = GetFakeNews().First();
            var user            = new ClaimsPrincipalFake(new Claim("role", "admin"));
            var dateTimeFactory = new DateTimeFactory();

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory);
                newsController.ControllerContext.HttpContext.User = user;

                // Act
                var result = newsController.Delete(1);

                // Assert
                Assert.IsType <OkResult>(result);
            }
        }
Esempio n. 13
0
        public async Task ReturnNotFoundWhenDelete()
        {
            // Assign
            var news            = GetFakeNews();
            int id              = 5;
            var dateTimeFactory = new DateTimeFactory();
            var fileServiceMock = new Mock <IFileStorageService>();

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory, fileServiceMock.Object);

                // Act
                var result = await newsController.Delete(id);

                // Assert
                Assert.IsType <NotFoundResult>(result);
            }
        }
Esempio n. 14
0
        public void ReturnForbidWhenUpdateOtherNews()
        {
            // Assign
            var oldNewsItem     = GetFakeNews().First();
            var newNewsItem     = GetFakeNews().First();
            var dateTimeFactory = new DateTimeFactory();

            newNewsItem.UserId = "connie.the.consultant";

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(oldNewsItem), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory);

                // Act
                var result = newsController.Put(1, new NewsViewModel(newNewsItem));

                // Assert
                Assert.IsType <ForbidResult>(result);
            }
        }
Esempio n. 15
0
        public async Task ValidModelStateWhenPosting()
        {
            // Assign
            var newsItem        = GetFakeNews().First();
            var newsItemVM      = new NewsViewModel(newsItem);
            var username        = "******";
            var user            = new ClaimsPrincipalFake(new Claim(ClaimTypes.NameIdentifier, username));
            var dateTimeFactory = new DateTimeFactory();
            var fileServiceMock = new Mock <IFileStorageService>();

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory, fileServiceMock.Object);
                newsController.ControllerContext.HttpContext.User = user;

                // Act
                var result = await newsController.Create(newsItemVM);

                // Assert
                Assert.True(result.ValidateActionRedirect("Details"));
            }
        }
Esempio n. 16
0
        public async Task RedirectWhenDeleteAsAdmin()
        {
            // Assign
            var news            = GetFakeNews().First();
            var user            = new ClaimsPrincipalFake(new Claim(ClaimTypes.Role, "Admin"));
            var dateTimeFactory = new DateTimeFactory();
            var fileServiceMock = new Mock <IFileStorageService>();

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory, fileServiceMock.Object);
                newsController.ControllerContext.HttpContext.User = user;

                // Act
                var result = await newsController.DeleteConfirmed(1);

                // Assert
                Assert.True(result.ValidateActionRedirect("Index"));
            }
        }
Esempio n. 17
0
        public async Task SetPublishDateWhenUpdateNews()
        {
            // Assign
            var dateTimeOffsetCreated      = new DateTimeOffset(2017, 7, 18, 0, 0, 0, TimeSpan.Zero);
            var dateTimeOffsetUpdated      = new DateTimeOffset(2017, 7, 19, 0, 0, 0, TimeSpan.Zero);
            var oldNewsItem                = GetFakeNews(dateTimeOffsetCreated).First();
            var newNewsItem                = GetFakeNews(dateTimeOffsetCreated).First();
            var dateTimeFactoryCreatedMock = new Mock <IDateTimeFactory>();
            var dateTimeFactoryUpdatedMock = new Mock <IDateTimeFactory>();
            var fileServiceMock            = new Mock <IFileStorageService>();

            dateTimeFactoryUpdatedMock.SetupGet(d => d.DateTimeOffsetUtc).Returns(dateTimeOffsetUpdated);

            var user = new ClaimsPrincipalFake(new Claim(ClaimTypes.NameIdentifier, "anne.the.admin"));

            oldNewsItem.Published = true;

            newNewsItem.UserId    = "anne.the.admin";
            newNewsItem.Published = true;

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(oldNewsItem), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactoryUpdatedMock.Object, fileServiceMock.Object);
                newsController.ControllerContext.HttpContext.User = user;

                // Act
                var result = await newsController.Edit(oldNewsItem.Id, new NewsViewModel(newNewsItem));
            }

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                // Assert
                Assert.Equal(context.News.First().Created, dateTimeOffsetCreated);
                Assert.Equal(context.News.First().Updated, dateTimeOffsetUpdated);
            }
        }
Esempio n. 18
0
        public async Task Edit_Category_Should_Return_Ok()
        {
            // Assign
            var category = new Category
            {
                Id    = 1,
                Title = "old category",
                Url   = "old-category",
            };

            var newCategory = new Category
            {
                Id    = 1,
                Title = "new category",
            };

            DbContextFake.SeedDb <IntranetApiContext>(c => c.Add(category));

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var categoryController = ControllerFake.GetController <CategoriesController>(context);

                // Act
                var result = await categoryController.Edit(1, newCategory);

                // Assert
                Assert.True(result.ValidateActionRedirect("Details"));
            }
            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var updatedCategory = context.Categories.Single();

                Assert.Equal(category.Title, "old category");
                Assert.Equal(category.Url, "old-category");
                Assert.Equal(updatedCategory.Title, "new category");
                Assert.Equal(updatedCategory.Url, "old-category");
            }
        }
Esempio n. 19
0
        public async Task ValidModelStateWhenDeleteOwnNews()
        {
            // Assign
            var news            = GetFakeNews().First();
            var user            = new ClaimsPrincipalFake(new Claim(ClaimTypes.NameIdentifier, "anne.the.admin"));
            var dateTimeFactory = new DateTimeFactory();
            var fileServiceMock = new Mock <IFileStorageService>();

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(news), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory, fileServiceMock.Object);
                newsController.ControllerContext.HttpContext.User = user;

                // Act
                var result = await newsController.Delete(1);

                // Assert
                Assert.IsType <ViewResult>(result);
                Assert.True(result.ModelStateIsValid());
            }
        }
Esempio n. 20
0
        public async Task ReturnInvalidModelStateWhenUpdateOtherNews()
        {
            // Assign
            var oldNewsItem     = GetFakeNews().First();
            var newNewsItem     = GetFakeNews().First();
            var dateTimeFactory = new DateTimeFactory();
            var fileServiceMock = new Mock <IFileStorageService>();

            newNewsItem.UserId = "connie.the.consultant";

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(oldNewsItem), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory, fileServiceMock.Object);

                // Act
                var result = await newsController.Edit(1, new NewsViewModel(newNewsItem));

                // Assert
                Assert.False(result.ModelStateIsValid());
            }
        }
Esempio n. 21
0
        public void ReturnOkResultWhenUpdateAsAdmin()
        {
            // Assign
            var oldNewsItem     = GetFakeNews().First();
            var newNewsItem     = GetFakeNews().First();
            var dateTimeFactory = new DateTimeFactory();
            var user            = new ClaimsPrincipalFake(new Claim("role", "admin"));

            newNewsItem.UserId = "anne.the.admin";

            DbContextFake.SeedDb <IntranetApiContext>(c => c.News.AddRange(oldNewsItem), ensureDeleted: true);

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var newsController = ControllerFake.GetController <NewsController>(context, dateTimeFactory);
                newsController.ControllerContext.HttpContext.User = user;

                // Act
                var result = newsController.Put(1, new NewsViewModel(newNewsItem));

                // Assert
                Assert.IsType <OkObjectResult>(result);
            }
        }
Esempio n. 22
0
        public async Task Create_Category_Should_Return_OkResult()
        {
            // Assign
            var category = new Category
            {
                Title = "title",
            };

            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                var categoryController = ControllerFake.GetController <CategoriesController>(context);

                // Act
                var response = await categoryController.Create(category);

                // Assert
                Assert.True(response.ValidateActionRedirect("Details"));
            }
            using (var context = DbContextFake.GetDbContext <IntranetApiContext>())
            {
                Assert.Equal("title", context.Categories.Single().Title);
                Assert.Equal("title", context.Categories.Single().Url);
            }
        }