Ejemplo n.º 1
0
        public void DeserializeProblem_NullFilePath_ThrowsArgumentException()
        {
            //Arrange
            var filesystem        = new FakeFileSystem();
            var problemSerializer = new ProblemSerializer(filesystem);

            //Act
            //Assert
            Assert.Throws <ArgumentException>(() => problemSerializer.DeserializeProblem(null));
        }
Ejemplo n.º 2
0
        public void DeserializeProblem_FileDoesNotExist_ThrowsInvalidOperationException()
        {
            //Arrange
            var filesystem        = new FakeFileSystem();
            var problemSerializer = new ProblemSerializer(filesystem);
            var filePath          = "c:\\File.3dPoC";

            //Act
            //Assert
            Assert.Throws <InvalidOperationException>(() => problemSerializer.DeserializeProblem(filePath));
        }
Ejemplo n.º 3
0
        public void SerializeProblem_NullModelProblem_ThrowsArgumentNullException()
        {
            //Arrange
            var filesystem        = new FakeFileSystem();
            var problemSerializer = new ProblemSerializer(filesystem);

            var filePath = "c:\\File.3dPoC";

            //Act
            //Assert
            Assert.Throws <ArgumentNullException>(() => problemSerializer.SerializeProblem(null, filePath));
        }
Ejemplo n.º 4
0
        public void DeserializeProblem_FileIsMalformed_ThrowsInvalidOperationException()
        {
            //Arrange
            var filesystem        = new FakeFileSystem();
            var problemSerializer = new ProblemSerializer(filesystem);
            var filePath          = "c:\\File.3dPoC";

            filesystem.ExistingFile        = filePath;
            filesystem.ExistingFileContent = string.Empty;

            //Act
            //Assert
            Assert.Throws <InvalidOperationException>(() => problemSerializer.DeserializeProblem(filePath));
        }
Ejemplo n.º 5
0
        public void SerializeProblem_FileDoesNotExist_ExpectFileCreated()
        {
            //Arrange
            var filesystem        = new FakeFileSystem();
            var problemSerializer = new ProblemSerializer(filesystem);

            var modelProblem = new ModelProblem("test");
            var filePath     = "c:\\File.3dPoC";

            //Act
            problemSerializer.SerializeProblem(modelProblem, filePath);

            //Assert
            Assert.That(filesystem.ExistingFile, Is.EqualTo(filePath));
        }
Ejemplo n.º 6
0
        public void SerializeProblem_ParentDirectoryDoesNotExist_ExpectDirectoryCreated()
        {
            //Arrange
            var filesystem        = new FakeFileSystem();
            var problemSerializer = new ProblemSerializer(filesystem);

            var modelProblem  = new ModelProblem("test");
            var directoryPath = "c:\\directory";
            var filePath      = $"{directoryPath}\\File.3dPoC";

            //Act
            problemSerializer.SerializeProblem(modelProblem, filePath);

            //Assert
            Assert.That(filesystem.CreatedDirectory, Is.EqualTo(directoryPath));
        }
Ejemplo n.º 7
0
        public void TestLoadProblem()
        {
            var ps = new ProblemSerializer();

            var problem = ps.LoadProblem(@"c:\users\tstivers\source\repos\icfp2016\problems\sample1.txt");

            Assert.That(problem.Silhouette.Polygons.Count, Is.EqualTo(1));
            Assert.That(problem.Silhouette.Polygons[0].Vertices.Count, Is.EqualTo(4));
            Assert.That(problem.Silhouette.Polygons[0].Vertices[0].X.A, Is.EqualTo(0));
            Assert.That(problem.Silhouette.Polygons[0].Vertices[0].X.B, Is.EqualTo(1));
            Assert.That(problem.Silhouette.Polygons[0].Vertices[1].X.A, Is.EqualTo(1));
            Assert.That(problem.Silhouette.Polygons[0].Vertices[1].X.B, Is.EqualTo(1));
            Assert.That(problem.Skeleton.Segments.Count, Is.EqualTo(5));
            Assert.That(problem.Skeleton.Segments[0].A.X.A, Is.EqualTo(0));
            Assert.That(problem.Skeleton.Segments[0].B.X.A, Is.EqualTo(1));
        }
Ejemplo n.º 8
0
        public void SerializeProblem_FileDoesNotExist_ExpectValidMementoCreated()
        {
            //Arrange
            var filesystem        = new FakeFileSystem();
            var problemSerializer = new ProblemSerializer(filesystem);

            var modelProblem = new ModelProblem("test");
            var filePath     = "c:\\File.3dPoC";

            //Act
            problemSerializer.SerializeProblem(modelProblem, filePath);

            //Assert
            var memento = filesystem.TryGetProblemMemento();

            Assert.That(memento, Is.Not.Null);
        }
Ejemplo n.º 9
0
        public void DeserializeProblem_FileIsValid_ExpectFileCorrectlyDeserialized()
        {
            //Arrange
            var    filesystem        = new FakeFileSystem();
            var    problemSerializer = new ProblemSerializer(filesystem);
            var    filePath          = "c:\\File.3dPoC";
            string fileContent       = "{ \"Name\" : \"DeserializeProblem\" }";

            filesystem.ExistingFile        = filePath;
            filesystem.ExistingFileContent = fileContent;

            //Act
            var modelProblem = problemSerializer.DeserializeProblem(filePath);

            //Assert
            Assert.That(modelProblem.Name, Is.EqualTo("DeserializeProblem"));
        }
Ejemplo n.º 10
0
        public void ProblemViewModel_SaveAndLoadIntegrationTest()
        {
            //Arrange
            var fileSystemMock    = new FakeFileSystem();
            var problemSerializer = new ProblemSerializer(fileSystemMock);
            var dialogService     = new FakeDialogService()
            {
                FilePath = "c:\\Test\\IntegrationTest.3DPoC"
            };

            var problemViewModel = new ProblemViewModel(new ModelProblem("OLD"), problemSerializer, dialogService);

            SetupProblemViewModel(problemViewModel);

            //Act
            problemViewModel.SaveProblemCommand.Execute(null);
            problemViewModel.LoadProblemCommand.Execute(null);

            //Assert
            Assert.That(fileSystemMock.ExistingFile, Is.Not.Null);
            Assert.That(fileSystemMock.ExistingFileContent, Is.Not.Null);
            Assert.That(fileSystemMock.CreatedDirectory, Is.Not.Null);
            AssertProblemViewModel(problemViewModel);
        }