Exemplo n.º 1
0
        public void CreateDelegates()
        {
            // Arrange.
            var date = new DateTime(2000, 1, 1);
            const string serializedTask = "serialized task";
            const string taskName = "task name";
            var parserResult = new ParserResult { Name = taskName };
            var taskVersion = new TaskVersion(date);
            var task = new Task(taskName);
            var parser = MockRepository.GenerateStrictMock<ITaskParser>();
            var store = MockRepository.GenerateStrictMock<ITaskStore>();

            var factory =
                MockRepository.GeneratePartialMock<TaskFactory>(parser, store);

            parser
                .Expect(p => p.Parse(serializedTask))
                .Return(parserResult);
            factory
                .Expect(f => f.New(date, parserResult))
                .Return(taskVersion);
            store
                .Expect(s => s.Save(taskName, taskVersion))
                .Return(task);

            // Act.
            var res = factory.Create(date, serializedTask);

            // Assert.
            parser.VerifyAllExpectations();
            factory.VerifyAllExpectations();
            store.VerifyAllExpectations();
            Assert.AreEqual(task, res);
        }
Exemplo n.º 2
0
        public void NewBasedOnParserResult()
        {
            // Arrange.
            var date = new DateTime();
            const string name = "Task name";
            const TaskStatus status = TaskStatus.Done;
            const TaskPriority priority = TaskPriority.Normal;
            var parserResult = new ParserResult
            {
                Name = name,
                Status = status,
                Priority = priority
            };

            var factory = new TaskFactory(
                MockRepository.GenerateStrictMock<ITaskParser>(),
                MockRepository.GenerateStrictMock<ITaskStore>()
            );

            // Act.
            var res = factory.New(date, parserResult);

            // Assert.
            Assert.AreEqual(priority, res.Priority);
            Assert.AreEqual(priority, res.Priority);
        }