예제 #1
0
 public ProjectCustomDataModel(ProjectCustomData customData)
 {
     ConfigurationName       = customData.ConfigurationName;
     ConfigurationType       = customData.ConfigurationType;
     SerializedConfiguration = customData.SerializedConfiguration;
     ProjectId = customData.ProjectId;
 }
        public void Can_Get_Number_Custom_Configuration_View()
        {
            // Arrange

            var customDataJsonConvertServiceMock = new Mock <ICustomDataJsonConvertService>();

            customDataJsonConvertServiceMock.Setup(
                m => m.DeserializeUser(ConfigurationType.Number, "serializedConfigurationMock"))
            .Returns(new NumberUserConfiguration
            {
                Value = 10
            });
            customDataJsonConvertServiceMock.Setup(
                m => m.DeserializeProject(ConfigurationType.Number, "projectSerializedConfiguration"))
            .Returns(new NumberProjectConfiguration
            {
                LowerBound = 0,
                UpperBound = 50
            });

            var userCustomDataRepositoryMock = new Mock <IUserCustomDataRepository>();

            userCustomDataRepositoryMock.Setup(
                m => m.GetUserCustomData(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
            .Returns(new UserCustomData
            {
                SerializedConfiguration = "serializedConfigurationMock"
            });

            var projectCustomDataMock = new ProjectCustomData
            {
                ConfigurationName       = "configurationName",
                SerializedConfiguration = "projectSerializedConfiguration"
            };
            var projectRepositoryMock = new Mock <IProjectRepository>();

            projectRepositoryMock.Setup(m => m.GetByIdWithCustomDatas(It.IsAny <int>())).Returns(new Project
            {
                Id = 1,
                ProjectCustomData = new List <ProjectCustomData>
                {
                    projectCustomDataMock
                }
            });

            // Act

            var target = new GetUserCustomDataConfigurationView(projectRepositoryMock.Object,
                                                                customDataJsonConvertServiceMock.Object, userCustomDataRepositoryMock.Object);
            var result = target.Invoke(1, 1, ConfigurationType.Number, "configurationName");

            // Assert

            Assert.IsType <NumberUserConfigurationView>(result);
            Assert.True(result.ProjectId == 1);
            Assert.True(result.UserId == 1);
            Assert.True(result.ConfigurationName == "configurationName");
            Assert.True(((NumberUserConfigurationView)result).CurrentValue == 10);
            Assert.True(((NumberUserConfigurationView)result).LowerBound == 0);
            Assert.True(((NumberUserConfigurationView)result).UpperBound == 50);
        }
        public void Can_Get_Text_Custom_Configuration_View()
        {
            // Arrange

            var customDataJsonConvertServiceMock = new Mock <ICustomDataJsonConvertService>();

            customDataJsonConvertServiceMock.Setup(
                m => m.DeserializeUser(ConfigurationType.Text, "serializedConfigurationMock"))
            .Returns(new TextUserConfiguration
            {
                Value = "default"
            });
            customDataJsonConvertServiceMock.Setup(
                m => m.DeserializeProject(ConfigurationType.Text, "projectSerializedConfiguration"))
            .Returns(new TextProjectConfiguration
            {
                PossibleValues = new HashSet <string>
                {
                    "first",
                    "second"
                }
            });

            var userCustomDataRepositoryMock = new Mock <IUserCustomDataRepository>();

            userCustomDataRepositoryMock.Setup(
                m => m.GetUserCustomData(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()))
            .Returns(new UserCustomData
            {
                SerializedConfiguration = "serializedConfigurationMock"
            });

            var projectCustomDataMock = new ProjectCustomData
            {
                ProjectId               = 1,
                ConfigurationName       = "configurationName",
                SerializedConfiguration = "projectSerializedConfiguration"
            };
            var projectRepositoryMock = new Mock <IProjectRepository>();

            projectRepositoryMock.Setup(m => m.GetByIdWithCustomDatas(It.IsAny <int>())).Returns(new Project
            {
                Id = 1,
                ProjectCustomData = new List <ProjectCustomData>
                {
                    projectCustomDataMock
                }
            });

            // Act

            var target = new GetUserCustomDataConfigurationView(projectRepositoryMock.Object,
                                                                customDataJsonConvertServiceMock.Object, userCustomDataRepositoryMock.Object);
            var result = target.Invoke(1, 1, ConfigurationType.Text, "configurationName");

            // Assert

            Assert.IsType <TextUserConfigurationView>(result);
            Assert.True(result.ProjectId == 1);
            Assert.True(result.UserId == 1);
            Assert.True(result.ConfigurationName == "configurationName");
            Assert.True(((TextUserConfigurationView)result).CurrentValue == "default");
            Assert.True(((TextUserConfigurationView)result).PossibleValuesList.Count == 3);
        }