public async Task And_Context_Is_Non_Controller_Then_No_Data_Is_Added_To_ViewBag(
            Guid userId,
            long accountId,
            [ArrangeActionContext] ActionExecutingContext context,
            [Frozen] Mock <ActionExecutionDelegate> nextMethod,
            GoogleAnalyticsFilter filter)
        {
            //Arrange
            var claim = new Claim(EmployeeClaims.Id, userId.ToString());

            context.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { claim }));
            context.RouteData.Values.Add("employerAccountId", accountId);

            var contextWithoutController = new ActionExecutingContext(
                new ActionContext(context.HttpContext, context.RouteData, context.ActionDescriptor),
                context.Filters,
                context.ActionArguments,
                "");

            //Act
            await filter.OnActionExecutionAsync(contextWithoutController, nextMethod.Object);

            //Assert
            Assert.DoesNotThrowAsync(() => filter.OnActionExecutionAsync(contextWithoutController, nextMethod.Object));
        }
コード例 #2
0
        public async Task Then_If_It_Is_An_Invalid_Base64_String_Then_Nothing_Is_Added(
            int providerPosition,
            int providerCount,
            uint providerId,
            [Greedy] CoursesController controller,
            [Frozen] Mock <IDataProtector> protector,
            [Frozen] Mock <IDataProtectionProvider> provider,
            [Frozen] Mock <ICookieStorageService <LocationCookieItem> > cookieStorageService,
            GoogleAnalyticsFilter filter)
        {
            // Arrange
            var data        = $"{providerPosition}|{providerCount}";
            var encodedData = Encoding.UTF8.GetBytes(data);

            protector.Setup(sut => sut.Unprotect(It.IsAny <byte[]>())).Returns(encodedData);
            provider.Setup(x => x.CreateProtector(Constants.GaDataProtectorName)).Returns(protector.Object);
            var context = SetupContextAndCookieLocations(controller, null, null, cookieStorageService, providerId.ToString(), data);

            //Act
            await filter.OnActionExecutionAsync(context, Mock.Of <ActionExecutionDelegate>());

            //Assert
            var viewBag = controller.ViewBag.GaData as GaData;

            Assert.IsNotNull(viewBag);
            viewBag.ProviderTotal.Should().Be(0);
            viewBag.ProviderPlacement.Should().Be(0);
            viewBag.ProviderId.Should().Be(0);
        }
        public async Task Then_If_Employer_Adds_The_AccountId_And_UserId_To_The_ViewBag_Data(
            Guid userId,
            long accountId,
            [ArrangeActionContext] ActionExecutingContext context,
            [Frozen] Mock <ActionExecutionDelegate> nextMethod,
            GoogleAnalyticsFilter filter)
        {
            //Arrange
            var claim = new Claim(EmployeeClaims.Id, userId.ToString());

            context.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { claim }));
            context.RouteData.Values.Add("AccountHashedId", accountId);

            //Act
            await filter.OnActionExecutionAsync(context, nextMethod.Object);

            //Assert
            var actualController = context.Controller as Controller;

            Assert.IsNotNull(actualController);
            var viewBagData = actualController.ViewBag.GaData as GaData;

            Assert.IsNotNull(viewBagData);
            Assert.AreEqual(accountId.ToString(), viewBagData.Acc);
            Assert.AreEqual(userId.ToString(), viewBagData.UserId);
        }
コード例 #4
0
        public async Task AndContextIsNonController_ThenNoDataIsAddedToViewbag(
            long ukPrn,
            string userId,
            [ArrangeActionContext] ActionExecutingContext context,
            [Frozen] Mock <ActionExecutionDelegate> nextMethod,
            GoogleAnalyticsFilter filter)
        {
            //Arrange
            var prnClaim  = new Claim(ProviderClaims.Ukprn, ukPrn.ToString());
            var userClaim = new Claim(ProviderClaims.Upn, userId);

            context.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { prnClaim, userClaim }));

            var contextWithoutController = new ActionExecutingContext(
                new ActionContext(context.HttpContext, context.RouteData, context.ActionDescriptor),
                context.Filters,
                context.ActionArguments,
                "");

            //Act
            await filter.OnActionExecutionAsync(contextWithoutController, nextMethod.Object);

            //Assert
            Assert.DoesNotThrowAsync(() => filter.OnActionExecutionAsync(contextWithoutController, nextMethod.Object));
        }
コード例 #5
0
        public async Task ThenProviderIdAndUserIdIsAddedToViewBag(
            uint ukPrn,
            string userId,
            [ArrangeActionContext] ActionExecutingContext context,
            [Frozen] Mock <ActionExecutionDelegate> nextMethod,
            GoogleAnalyticsFilter filter)
        {
            //Arrange
            var prnClaim  = new Claim(ProviderClaims.Ukprn, ukPrn.ToString());
            var userClaim = new Claim(ProviderClaims.Upn, userId.ToString());

            context.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { prnClaim, userClaim }));

            //Act
            await filter.OnActionExecutionAsync(context, nextMethod.Object);

            //Assert
            var actualController = context.Controller as Controller;

            Assert.IsNotNull(actualController);
            var viewBagData = actualController.ViewBag.GaData as GaData;

            Assert.IsNotNull(viewBagData);
            Assert.AreEqual(ukPrn.ToString(), viewBagData.UkPrn);
            Assert.AreEqual(userId, viewBagData.UserId);
        }
コード例 #6
0
        public async Task Then_If_No_Location_In_Context_Or_Cookie_Location_Is_Not_Added_To_The_ViewBag(
            [Greedy] CoursesController controller,
            [Frozen] Mock <ICookieStorageService <LocationCookieItem> > cookieStorageService,
            GoogleAnalyticsFilter filter)
        {
            // Arrange
            var context = SetupContextAndCookieLocations(controller, null, null, cookieStorageService);

            //Act
            await filter.OnActionExecutionAsync(context, Mock.Of <ActionExecutionDelegate>());

            //Assert
            var viewBag = controller.ViewBag.GaData as GaData;

            viewBag.Should().BeEquivalentTo(new GaData());
        }
コード例 #7
0
        Then_If_No_Location_In_Context_And_Location_In_Cookie_Adds_The_Location_From_The_Cookie_To_The_ViewBag(
            LocationCookieItem location,
            [Frozen] Mock <ICookieStorageService <LocationCookieItem> > cookieStorageService,
            [Greedy] CoursesController controller,
            GoogleAnalyticsFilter filter)
        {
            //Arrange
            var context = SetupContextAndCookieLocations(controller, null, location, cookieStorageService);

            //Act
            await filter.OnActionExecutionAsync(context, Mock.Of <ActionExecutionDelegate>());

            //Assert
            var viewBag = controller.ViewBag.GaData as GaData;

            Assert.IsNotNull(viewBag);
            Assert.AreEqual(location.Name, viewBag.Location);
        }
コード例 #8
0
        public async Task Then_If_The_Request_Has_A_Location_Adds_The_Location_To_The_ViewBag(
            string location,
            [Frozen] Mock <ICookieStorageService <LocationCookieItem> > cookieStorageService,
            [Greedy] CoursesController controller,
            GoogleAnalyticsFilter filter)
        {
            //Arrange
            var context =
                SetupContextAndCookieLocations(controller, location, null, cookieStorageService);

            //Act
            await filter.OnActionExecutionAsync(context, Mock.Of <ActionExecutionDelegate>());

            //Assert
            var viewBag = controller.ViewBag.GaData as GaData;

            Assert.IsNotNull(viewBag);
            Assert.AreEqual(location, viewBag.Location);
        }
        public async Task Then_If_Provider_Adds_The_ProviderId_To_The_ViewBag_Data(
            uint ukprn,
            [Frozen] ServiceParameters serviceParameters,
            [ArrangeActionContext] ActionExecutingContext context,
            [Frozen] Mock <ActionExecutionDelegate> nextMethod,
            GoogleAnalyticsFilter filter)
        {
            //Arrange
            context.RouteData.Values.Add("ukPrn", ukprn);
            serviceParameters.AuthenticationType = AuthenticationType.Provider;

            //Act
            await filter.OnActionExecutionAsync(context, nextMethod.Object);

            //Assert
            var actualController = context.Controller as Controller;

            Assert.IsNotNull(actualController);
            var viewBagData = actualController.ViewBag.GaData as GaData;

            Assert.IsNotNull(viewBagData);
            Assert.AreEqual(ukprn.ToString(), viewBagData.UkPrn);
        }
        public async Task Then_If_User_Is_Not_Logged_In_Then_Empty_ViewBag_Data_Is_Returned(
            long accountId,
            [Frozen] ServiceParameters serviceParameters,
            [ArrangeActionContext] ActionExecutingContext context,
            [Frozen] Mock <ActionExecutionDelegate> nextMethod,
            GoogleAnalyticsFilter filter)
        {
            //Arrange
            context.HttpContext.User             = new ClaimsPrincipal(new ClaimsIdentity());
            serviceParameters.AuthenticationType = AuthenticationType.Employer;

            //Act
            await filter.OnActionExecutionAsync(context, nextMethod.Object);

            //Assert
            var actualController = context.Controller as Controller;

            Assert.IsNotNull(actualController);
            var viewBagData = actualController.ViewBag.GaData as GaData;

            Assert.IsNotNull(viewBagData);
            Assert.IsNull(viewBagData.Acc);
            Assert.IsNull(viewBagData.UserId);
        }