public void DateDelegates() { // Arrange. var date = new DateTime(2010, 1, 1); var task = MockRepository.GeneratePartialMock <Task>("task name"); var versions = new[] { new TaskVersion(date) }; task.Expect(t => t.Versions).Return(versions); // Act. var res = task.Date; // Assert. task.VerifyAllExpectations(); Assert.AreEqual(date, res); }
public void Parse_NoTokens_Null() { // Arrange. var task = "task"; var parser = MockRepository.GeneratePartialMock <TaskParser>(); parser .Expect(p => p.GetTokens(task)) .Return(null); // Act. var res = parser.Parse(task); // Assert. parser.VerifyAllExpectations(); Assert.IsNull(res); }
public void PriorityDelegates() { // Arrange. var priority = TaskPriority.High; var task = MockRepository.GeneratePartialMock <Task>("task name"); var versions = new[] { new TaskVersion(new DateTime()) { Priority = priority } }; task.Expect(t => t.Versions).Return(versions); // Act. var res = task.Priority; // Assert. task.VerifyAllExpectations(); Assert.AreEqual(priority, res); }
public void StatusDelegates() { // Arrange. var status = TaskStatus.Done; var task = MockRepository.GeneratePartialMock <Task>("task name"); var versions = new[] { new TaskVersion(new DateTime()) { Status = status } }; task.Expect(t => t.Versions).Return(versions); // Act. var res = task.Status; // Assert. task.VerifyAllExpectations(); Assert.AreEqual(status, res); }
public void Parse_Delegates() { // Arrange. const string task = "task"; var tokens = Tuple.Create <string, string, string>( "priority", "status", "name" ); var expectedPriority = TaskPriority.High; var expectedStatus = TaskStatus.Done; const string expectedName = "name"; var parser = MockRepository.GeneratePartialMock <TaskParser>(); parser .Expect(p => p.GetTokens(task)) .Return(tokens); parser .Expect(p => p.ParsePriority(tokens.Item1)) .Return(expectedPriority); parser .Expect(p => p.ParseStatus(tokens.Item2)) .Return(expectedStatus); parser .Expect(p => p.ParseName(tokens.Item3)) .Return(expectedName); // Act. var res = parser.Parse(task); // Assert. parser.VerifyAllExpectations(); Assert.AreEqual(expectedPriority, res.Priority); Assert.AreEqual(expectedStatus, res.Status); Assert.AreEqual(expectedName, res.Name); }
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]); }
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); }