コード例 #1
0
            public void ProjectDataFactory_CreateProjectDataFromStream_Test()
            {
                // Arrange
                var expectedName = mockProjectName;
                var expectedRaw  = mockProjectLines.Select(x => x.Raw);
                var writeStream  = new MemoryStream();

                using (StreamWriter writer = new StreamWriter(writeStream))
                {
                    foreach (var line in expectedRaw)
                    {
                        writer.WriteLine(line);
                    }
                    writer.Flush();
                }

                var readStream = new MemoryStream(writeStream.ToArray());
                var reader     = new StreamReader(readStream);

                // Act
                var projectData = projectDataFactory.CreateProjectDataFromStream(expectedName, reader);
                var actualName  = projectData.ProjectName;
                var actualRaw   = projectData.ProjectLines.Select(x => x.Raw).ToList();

                // Assert
                Assert.IsType <ProjectData>(projectData);
                Assert.IsAssignableFrom <IProjectData>(projectData);
                Assert.IsType <string>(actualName);
                Assert.Equal(expectedName, actualName);
                Assert.IsType <List <string> >(actualRaw);
                Assert.Equal(expectedRaw, actualRaw);
            }
コード例 #2
0
        /// <summary>
        /// Creates translation data from stream reader.
        /// </summary>
        /// <param name="fileName">The name of the file.</param>
        /// <param name="sr">The stream reader used to read the file.</param>
        /// <returns>Object that implements Translation Data Interface.</returns>
        public ITranslationData CreateTranslationDataFromStream(string fileName, StreamReader sr)
        {
            try
            {
                var project = _projectDataFactory.CreateProjectDataFromStream(fileName, sr);

                var translationData = CreateTranslationDataFromProject(project);
                translationData.DataChanged = false;
                return(translationData);
            }
            catch (System.Exception e)
            {
                throw e;
            }
        }
コード例 #3
0
            public void ProjectDataFactory_GivenEmptyStreamRaiseException()
            {
                // Arrange
                var emptyStream = new StreamReader(new MemoryStream());

                var expectedMessage = "No Raw Lines were submitted into the project.";
                var expected        = new EmptyRawException(expectedMessage);

                // Act
                var actual        = Record.Exception(() => projectDataFactory.CreateProjectDataFromStream(mockProjectName, emptyStream));
                var actualMessage = actual.Message;

                // Assert
                Assert.IsType <EmptyRawException>(actual);
                Assert.NotStrictEqual(expected, actual);
                Assert.IsType <string>(actualMessage);
                Assert.Equal(expectedMessage, actual.Message);
            }