Ejemplo 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);
        }
Ejemplo n.º 2
0
        public void GetTasks()
        {
            // Arrange.
            const string taskName = "task name";
            var task = new Task(taskName);

            var date = new DateTime();
            var taskVersion = new TaskVersion(date);

            var versions = new SortedDictionary<DateTime, TaskVersion>();
            versions.Add(date, taskVersion);

            var taskVersions = new Dictionary<
                string, SortedDictionary<DateTime, TaskVersion>
            >();
            taskVersions.Add(taskName, versions);

            var store = MockRepository.GeneratePartialMock<MemoryTaskStore>();

            store.Expect(s => s.TaskVersions).Return(taskVersions);
            store.Expect(s => s.New(taskName, versions)).Return(task);

            // Act.
            var res = store.Tasks.ToList();

            // Assert.
            store.VerifyAllExpectations();
            Assert.AreEqual(1, res.Count());
            Assert.AreEqual(task, res.First());
        }
Ejemplo n.º 3
0
        public void GetName()
        {
            // Arrange.
            const string name = "task name";
            var task = new Task(name);

            // Act.
            var res = task.Name;

            // Assert.

            Assert.AreEqual(task.Name, res);
        }
Ejemplo n.º 4
0
        public void SaveCreatesTaskAndAppendsVersion()
        {
            // Arrange.
            const string name = "task name";
            var date = new DateTime(2000, 1, 1);
            var version = new TaskVersion(date);
            var task = new Task(name);
            var versions = new SortedDictionary<DateTime, TaskVersion>();
            var store = MockRepository.GeneratePartialMock<MemoryTaskStore>();

            store.Expect(s => s.GetVersions(name)).Return(versions);
            store.Expect(s => s.New(name, versions)).Return(task);

            // Act.
            var res = store.Save(name, version);

            // Assert.
            store.VerifyAllExpectations();
            Assert.AreEqual(task, res);
            Assert.AreEqual(1, versions.Count());
            Assert.AreEqual(version, versions[date]);
        }