Exemplo n.º 1
0
        public async Task TestGetCurrentUser()
        {
            IUserProfileService         _UserProfileProvider = new MockUserProfileService(graphUri, clientId2, appKey, AADInstance);
            ILogger <UserApiController> _logger1             = new LoggerFactory().CreateLogger <UserApiController>();

            UserApiController userApiController = new UserApiController(_UserProfileProvider, _logger1);

            var actionResult = await userApiController.GetCurrentUser();

            actionResult.AssertOkValueType <User>();

            var result = actionResult.OkayContent <User>();;

            Assert.Equal("*****@*****.**", result.Id);
        }
Exemplo n.º 2
0
        public void UserController_ShouldReturnCurrentUser()
        {
            TestDbPopulator.PopulateUsers(2);
            TestDbPopulator.PopulateStandartAccounts(2);
            _user = TestDbPopulator.GetUser(1);
            var req = new StandartAuthRequest
            {
                Email    = _user.Email,
                Password = "******"
            };

            string token   = BaseAuth.CreateToken("u1");
            var    config  = new HttpConfiguration();
            var    request = new HttpRequestMessage {
                RequestUri = new Uri("http://localhost:50268/api/User")
            };

            request.Headers.Add("x-zumo-auth", token);
            request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
            var username            = "******";
            var identity            = new GenericIdentity(username, "");
            var nameIdentifierClaim = new Claim(ClaimTypes.NameIdentifier, username);

            identity.AddClaim(nameIdentifierClaim);
            var principal = new GenericPrincipal(identity, new string[] {});
            var user      = new ClaimsPrincipal(principal);

            _controller = new UserApiController(TestContext)
            {
                Request = request,
                User    = user
            };
            var response = _controller.GetCurrentUser();
            var result   = TestHelper.ParseUserResponse(response);

            Assert.AreEqual("OK", result.StatusCode);
        }
Exemplo n.º 3
0
        public async Task TestAddTemplate()
        {
            ICosmosDBRepository <Template>  _RepoTemplate        = new CosmosDBRepository <Template>(endpoint, authkey, database, colTemplate);
            ICosmosDBRepository <Category>  _RepoCategory        = new CosmosDBRepository <Category>(endpoint, authkey, database, colTemplate);
            IUserProfileService             _UserProfileProvider = new MockUserProfileService(graphUri, clientId2, appKey, AADInstance);
            ILogger <TemplateApiController> _logger  = new LoggerFactory().CreateLogger <TemplateApiController>();
            ILogger <UserApiController>     _logger1 = new LoggerFactory().CreateLogger <UserApiController>();

            TemplateApiController templateApiController = new TemplateApiController(_RepoTemplate, _RepoCategory, _UserProfileProvider, _logger);
            UserApiController     userApiController     = new UserApiController(_UserProfileProvider, _logger1);

            var actionUserResult = await userApiController.GetCurrentUser();

            var userResult = actionUserResult.OkayContent <User>();

            var actionResult = await templateApiController.CreateUserTemplate(new Template()
            {
                Name = "TemplateTest"
            });

            actionResult.AssertOkValueType <string>();

            string templateId = actionResult.OkayContent <string>();

            Assert.NotNull(templateId);

            var actionResult2 = await templateApiController.GetTemplateById(templateId);

            actionResult2.AssertOkValueType <Template>();

            var result2 = actionResult2.OkayContent <Template>();;

            Assert.Equal(templateId, result2.Id);
            Assert.Equal(TemplateDocumentType.User, result2.DocType);
            Assert.Equal(userResult.Id.ToLower(), result2.UserId);
        }