Example #1
0
        public async Task TestGetTemplateById()
        {
            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>();

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

            var actionResult = await templateApiController.GetTemplateById("refrigerator_smart");

            actionResult.AssertOkValueType <Template>();

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

            Assert.Equal("refrigerator_smart", result.Id);
            Assert.Equal(TemplateDocumentType.CommonTemplate, result.DocType);
        }
Example #2
0
        public async Task TestDeleteCommonTemplate()
        {
            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>();

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

            var actionResult = await templateApiController.GetTemplateById("refrigerator_smart");

            actionResult.AssertOkValueType <Template>();

            var toDelete = actionResult.OkayContent <Template>();

            var actionResult2 = await templateApiController.DeleteUserTemplate(toDelete.Id); //Should fail because you can't delete a common template

            Assert.IsAssignableFrom <StatusCodeResult>(actionResult2);
        }
Example #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);
        }