Exemplo n.º 1
0
        public void ShouldGetAllFavouritesFromFavouritesCollection()
        {
            // Arrange
            var cookies = new FakeCookie(true);

            httpContextAccessor.Setup(_ => _.HttpContext.Request.Cookies).Returns(cookies);
            httpContextAccessor.Setup(_ => _.HttpContext.Response.Cookies).Returns(cookies);

            // Act
            var favourites = cookiesHelper.GetCookies <Group>("favourites");

            // Assert
            favourites.Should().HaveCount(3);
        }
Exemplo n.º 2
0
        public void ShouldRemoveAllFromFavouritesCollection()
        {
            // Arrange
            var cookies = new FakeCookie(true);

            httpContextAccessor.Setup(_ => _.HttpContext.Request.Cookies).Returns(cookies);
            httpContextAccessor.Setup(_ => _.HttpContext.Response.Cookies).Returns(cookies);

            // Act
            cookiesHelper.RemoveAllFromCookies <Group>("favourites");
            var result = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(cookies["favourites"]);

            // Assert
            result.ContainsKey(typeof(Group).ToString()).Should().Be(false);
        }
Exemplo n.º 3
0
        public void ShouldAddToFavouritesCollection()
        {
            // Arrange
            var cookies = new FakeCookie();

            httpContextAccessor.Setup(_ => _.HttpContext.Request.Cookies).Returns(cookies);
            httpContextAccessor.Setup(_ => _.HttpContext.Response.Cookies).Returns(cookies);

            // Act
            cookiesHelper.AddToCookies <Group>("test1", "favourites");
            cookiesHelper.AddToCookies <Event>("test2", "favourites");
            var result = JsonConvert.DeserializeObject <Dictionary <string, List <string> > >(cookies["favourites"]);

            // Assert
            result[typeof(Group).ToString()].Should().Equal(@"test1");
            result[typeof(Event).ToString()].Should().Equal(@"test2");
        }
Exemplo n.º 4
0
        public void ShouldPopulateFavouritePropertyToCollectionWhencallingPopulateFavourites()
        {
            // Arrange
            var cookies = new FakeCookie(true);

            var groups = new List <Group>()
            {
                new GroupBuilder().Slug("test1").Build(),
                new GroupBuilder().Build()
            };

            httpContextAccessor.Setup(_ => _.HttpContext.Request.Cookies).Returns(cookies);

            // Act
            groups = cookiesHelper.PopulateCookies(groups, "favourites");

            // Assert
            groups[0].Favourite.Should().Be(true);
            groups[1].Favourite.Should().Be(false);
        }