public void Can_Add()
        {
            //Arrange
            var orgId        = A <int>();
            var overviewType = A <OverviewType>();
            var config       = A <string>();
            var kendoConfig  = new KendoOrganizationalConfiguration
            {
                Configuration  = config,
                OrganizationId = orgId,
                OverviewType   = overviewType
            };

            _repository.Setup(x => x.Get(orgId, overviewType)).Returns(Maybe <KendoOrganizationalConfiguration> .None);
            _repository.Setup(x => x.Add(It.IsAny <KendoOrganizationalConfiguration>())).Returns(kendoConfig);
            _authorizationContext.Setup(x => x.AllowCreate <KendoOrganizationalConfiguration>(orgId)).Returns(true);

            //Act
            var createResult = _sut.CreateOrUpdate(orgId, overviewType, config);

            //Assert
            Assert.True(createResult.Ok);
            var configuration = createResult.Value;

            Assert.Same(configuration, kendoConfig);
        }
        public void Can_Update()
        {
            //Arrange
            var orgId        = A <int>();
            var overviewType = A <OverviewType>();
            var config       = A <string>();
            var kendoConfig  = new KendoOrganizationalConfiguration
            {
                Configuration  = A <string>(),
                OrganizationId = orgId,
                OverviewType   = overviewType
            };

            _repository.Setup(x => x.Get(orgId, overviewType)).Returns(kendoConfig);
            _authorizationContext.Setup(x => x.AllowModify(kendoConfig)).Returns(true);

            //Act
            var updateResult = _sut.CreateOrUpdate(orgId, overviewType, config);

            //Assert
            _repository.Verify(x => x.Update(It.IsAny <KendoOrganizationalConfiguration>()), Times.Once);

            Assert.True(updateResult.Ok);
            var configuration = updateResult.Value;

            Assert.Equal(configuration.Configuration, config);
            Assert.Equal(configuration.OrganizationId, orgId);
            Assert.Equal(configuration.OverviewType, overviewType);
        }
Esempio n. 3
0
        public KendoOrganizationalConfiguration Add(KendoOrganizationalConfiguration createdConfig)
        {
            var config = _repository.Insert(createdConfig);

            _repository.Save();
            return(config);
        }
        public Result <KendoOrganizationalConfiguration, OperationError> CreateOrUpdate(int organizationId, OverviewType overviewType, string configuration)
        {
            var currentConfig = _kendoOrganizationRepository.Get(organizationId, overviewType);

            if (currentConfig.HasValue)
            {
                var modifiedConfig = currentConfig.Value;
                if (!_authorizationContext.AllowModify(modifiedConfig))
                {
                    return(new OperationError(OperationFailure.Forbidden));
                }

                modifiedConfig.Configuration = configuration;
                _kendoOrganizationRepository.Update(modifiedConfig);
                return(modifiedConfig);
            }

            if (!_authorizationContext.AllowCreate <KendoOrganizationalConfiguration>(organizationId))
            {
                return(new OperationError(OperationFailure.Forbidden));
            }

            var createdConfig = new KendoOrganizationalConfiguration
            {
                OrganizationId = organizationId,
                OverviewType   = overviewType,
                Configuration  = configuration
            };
            var created = _kendoOrganizationRepository.Add(createdConfig);

            return(created);
        }
 private static KendoOrganizationalConfigurationDTO Map(KendoOrganizationalConfiguration value)
 {
     return(new KendoOrganizationalConfigurationDTO
     {
         OrganizationId = value.OrganizationId,
         OverviewType = value.OverviewType,
         Configuration = value.Configuration
     });
 }
Esempio n. 6
0
        public void Can_Update()
        {
            //Arrange
            var config = new KendoOrganizationalConfiguration();

            //Act
            _sut.Update(config);

            //Assert
            VerifySaved();
            _repository.Verify(x => x.Update(config), Times.Once);
        }
Esempio n. 7
0
        public void Can_Add()
        {
            //Arrange
            var config = new KendoOrganizationalConfiguration();

            _repository.Setup(x => x.Insert(config)).Returns <KendoOrganizationalConfiguration>(x => x);

            //Act
            var configuration = _sut.Add(config);

            //Assert
            Assert.Same(config, configuration);
            VerifySaved();
        }
        public void Can_Get()
        {
            //Arrange
            var orgId        = A <int>();
            var overviewType = A <OverviewType>();
            var kendoConfig  = new KendoOrganizationalConfiguration
            {
                Configuration  = A <string>(),
                OrganizationId = orgId,
                OverviewType   = overviewType
            };

            _repository.Setup(x => x.Get(orgId, overviewType)).Returns(kendoConfig);

            //Act
            var getResult = _sut.Get(orgId, overviewType);

            //Assert
            Assert.True(getResult.Ok);
            Assert.Equal(kendoConfig, getResult.Value);
        }
        public void Can_Delete()
        {
            //Arrange
            var orgId        = A <int>();
            var overviewType = A <OverviewType>();
            var kendoConfig  = new KendoOrganizationalConfiguration
            {
                Configuration  = A <string>(),
                OrganizationId = orgId,
                OverviewType   = overviewType
            };

            _repository.Setup(x => x.Get(orgId, overviewType)).Returns(kendoConfig);
            _authorizationContext.Setup(x => x.AllowDelete(kendoConfig)).Returns(true);

            //Act
            var deleteResult = _sut.Delete(orgId, overviewType);

            //Assert
            Assert.True(deleteResult.Ok);
            Assert.Equal(kendoConfig, deleteResult.Value);
        }
        public void Delete_Fails_If_Not_Allowed_To_Delete()
        {
            //Arrange
            var orgId        = A <int>();
            var overviewType = A <OverviewType>();
            var config       = A <string>();
            var kendoConfig  = new KendoOrganizationalConfiguration
            {
                Configuration  = A <string>(),
                OrganizationId = orgId,
                OverviewType   = overviewType
            };

            _repository.Setup(x => x.Get(orgId, overviewType)).Returns(kendoConfig);
            _authorizationContext.Setup(x => x.AllowDelete(kendoConfig)).Returns(false);

            //Act
            var deleteResult = _sut.Delete(orgId, overviewType);

            //Assert
            Assert.True(deleteResult.Failed);
            Assert.Equal(OperationFailure.Forbidden, deleteResult.Error.FailureType);
            _repository.Verify(x => x.Delete(It.IsAny <KendoOrganizationalConfiguration>()), Times.Never);
        }
        public void Add_Fails_If_Not_Allowed_To_Create()
        {
            //Arrange
            var orgId        = A <int>();
            var overviewType = A <OverviewType>();
            var config       = A <string>();
            var kendoConfig  = new KendoOrganizationalConfiguration
            {
                Configuration  = config,
                OrganizationId = orgId,
                OverviewType   = overviewType
            };

            _repository.Setup(x => x.Get(orgId, overviewType)).Returns(Maybe <KendoOrganizationalConfiguration> .None);
            _repository.Setup(x => x.Add(It.IsAny <KendoOrganizationalConfiguration>())).Returns(kendoConfig);
            _authorizationContext.Setup(x => x.AllowCreate <KendoOrganizationalConfiguration>(orgId)).Returns(false);

            //Act
            var createResult = _sut.CreateOrUpdate(orgId, overviewType, config);

            //Assert
            Assert.True(createResult.Failed);
            Assert.Equal(OperationFailure.Forbidden, createResult.Error.FailureType);
        }
Esempio n. 12
0
 public void Update(KendoOrganizationalConfiguration modifiedConfig)
 {
     _repository.Update(modifiedConfig);
     _repository.Save();
 }
Esempio n. 13
0
 public void Delete(KendoOrganizationalConfiguration configToDelete)
 {
     _repository.Delete(configToDelete);
     _repository.Save();
 }