Exemple #1
0
        public async Task Serialize_AsExpected()
        {
            JsonSerializerWrapper jsonSerializerWrapper = new JsonSerializerWrapper();

            TaskGroupFactory tasksGroupFactory = new TaskGroupFactory(
                A.Fake <IIDProducer>(), NullLogger <TaskGroupFactory> .Instance);

            OperationResult <ITasksGroup> tasksGroupA = tasksGroupFactory.CreateGroup("a group", mTasksGroupProducer);

            tasksGroupFactory.CreateTask(tasksGroupA.Value, "task 1", mWorkTaskProducer);

            OperationResult <ITasksGroup> tasksGroupB = tasksGroupFactory.CreateGroup("b group", mTasksGroupProducer);

            tasksGroupFactory.CreateTask(tasksGroupB.Value, "task 3", mWorkTaskProducer);

            List <ITasksGroup> entities = new List <ITasksGroup>
            {
                tasksGroupA.Value, tasksGroupB.Value
            };

            string tempSerializedFile = Path.GetRandomFileName();

            try
            {
                await jsonSerializerWrapper.Serialize(entities, tempSerializedFile).ConfigureAwait(false);

                string text = await File.ReadAllTextAsync(tempSerializedFile).ConfigureAwait(false);

                Assert.Contains("\"GroupName\": \"a group\"", text);
                Assert.Contains("\"Description\": \"task 1\"", text);
                Assert.Contains("\"GroupName\": \"b group\"", text);
                Assert.Contains("\"Description\": \"task 3\"", text);
            }
            finally
            {
                File.Delete(tempSerializedFile);
            }
        }