public void Test() { var ids = new List <int> { 1, 2, 3 }; var authors = new List <string> { "a", "b", "c" }; var article = new Article { Ids = ids, Authors = authors }; var memento = Memento.Create() .Register(article); article.Ids.Remove(2); article.Ids.Add(4); article.Authors.Remove("b"); article.Authors.Add("d"); memento.Rollback(); CollectionAssert.AreEqual(new List <int> { 1, 2, 3 }, article.Ids); CollectionAssert.AreEqual(new List <string> { "a", "c", "d" }, article.Authors); }
public void Test() { var article1 = new Article { Author = "DCastro" }; var article2 = new Article { Author = "JBarbosa" }; var articles = new HashSet <Article> { article1, article2 }; var memento = Memento.Create() .RegisterCollection(articles); articles.Remove(article2); memento.Rollback(); Assert.AreEqual(2, articles.Count); CollectionAssert.Contains(articles, article1); CollectionAssert.Contains(articles, article2); }
public void Test() { var author = new Author { Name = "DCastro" }; var article = new Article { Authors = new List <ICollection <Author> > { new Collection <Author> { author } } }; var memento = Memento.Create() .Register(article); article.Authors[0] = null; article.Authors = null; author.Name = "No one"; memento.Rollback(); Assert.NotNull(article.Authors); Assert.AreEqual(1, article.Authors.Count); Assert.NotNull(article.Authors[0]); Assert.AreEqual(1, article.Authors[0].Count); CollectionAssert.AreEqual("DCastro", article.Authors.First().First().Name); }
public void TestFailSilently() { Article article = new Article { Pages = new BlockingCollection <int>( new ConcurrentQueue <int>( new[] { 1, 2, 3 }) ) }; //Act var memento = Memento.Create() .Register(article); int ignore; article.Pages.TryTake(out ignore); article.Pages.TryTake(out ignore); article.Pages.CompleteAdding(); memento.Rollback(); //Assert CollectionAssert.AreEquivalent(new[] { 3 }, article.Pages); }
public void WithMementoCollection() { var author1 = new Author { Name = "DCastro" }; var author2 = new Author { Name = "JBarbosa" }; var article = new Article { Authors = new Queue <Author>(new[] { author1, author2 }) }; var memento = Memento.Create() .Register(article); article.Authors.Dequeue(); author1.Name = "No one"; author2.Name = "No one"; memento.Rollback(); CollectionAssert.AreEqual(new[] { author1, author2 }, article.Authors); Assert.AreEqual("DCastro", author1.Name); Assert.AreEqual("JBarbosa", author2.Name); }
public IElement this[int index] { get { Memento memento = this.items[index]; return(memento.IsReal ? memento.Element : memento.Create()); } set { throw new NotSupportedException("Please use the overload that takes a template"); } }
public void TestRegisterCollection() { int[] numbers = { 1, 2, 3 }; var memento = Memento.Create() .RegisterCollection(numbers); numbers[1] = 9; memento.Rollback(); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, numbers); }
public void Test() { Article.Count = 1; var memento = Memento.Create() .RegisterProperty(() => Article.Count); Article.Count++; memento.Rollback(); Assert.AreEqual(1, Article.Count); }
public void Test() { Article article = new Article { Title = "Draft" }; var memento = Memento.Create() .Register(article); article.Title = "Something else"; memento.Rollback(); Assert.AreEqual("Draft", article.Title); }
public void Test() { Article.Count = new Count { Views = 1 }; var memento = Memento.Create() .RegisterProperty(() => Article.Count.Views); Article.Count.Views++; memento.Rollback(); Assert.AreEqual(1, Article.Count.Views); }
public void Test() { var article = new Article("Draft", 1, "DCastro"); var memento = Memento.Create() .Register(article); article.ChangeState("Something else", 2, "No one"); memento.Rollback(); Assert.AreEqual("Draft", article.GetTitle()); Assert.AreEqual(1, article.GetId()); Assert.AreEqual("DCastro", article.GetAuthor()); }
public void Test() { var article = new Article(); Article.Count = 1; var memento = Memento.Create() .Register(article); Article.Count++; memento.Rollback(); Assert.AreEqual(1, Article.Count); }
public void Test() { Article article = new Article { Pages = new Queue <int>( new[] { 1, 2, 3 }) }; //Act var memento = Memento.Create(); var ex = Assert.Throws <CollectionException>(() => memento.Register(article)); StringAssert.Contains("ICollectionAdapter", ex.Message); }
public void TestDoesntRestoreRegularProperty() { var article = new Article { Id = 1 }; var memento = Memento.Create() .Register(article); article.Id = 2; memento.Rollback(); Assert.AreEqual(2, article.Id); }
public void Test() { var article = new Article { Pages = new SetMock <int> { 1, 2, 3 } }; var memento = Memento.Create() .Register(article); memento.Rollback(); Assert.True(((SetMock <int>)article.Pages).UnionWithCalled); }
public void Test() { var article = new Article { Ids = new ExplicitCollection(new[] { 1, 2, 3 }) }; var memento = Memento.Create() .Register(article); (article.Ids as ICollection <int>).Remove(2); memento.Rollback(); CollectionAssert.AreEqual(new[] { 1, 2, 3 }, article.Ids); }
public void Test() { IArticle <string> article = new Article { Title = "Draft", Id = 1 }; var memento = Memento.Create() .Register(article); (article as Article).Title = "Something else"; (article as Article).Id = 2; memento.Rollback(); Assert.AreEqual("Draft", article.Title); Assert.AreEqual(1, (article as Article).Id); }
public void Test() { var author = new Author { Name = "DCastro" }; var article = new Article { Author = author }; var memento = Memento.Create() .Register(article); author.Name = "No one"; memento.Rollback(); Assert.AreEqual("No one", article.Author.Name); }
public void Test() { Article article = new Article { Pages = new[] { 1, 2, 3 } }; //Act var memento = Memento.Create() .Register(article); article.Pages[1] = 9; article.Pages[2] = 8; memento.Rollback(); //Assert CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, article.Pages); }
public void TestTypeAsConversion() { var article = new Article { Author = new Person { Name = "DCastro" } }; var memento = Memento.Create() .RegisterProperty(article, a => (a.Author as Person).Name); ((Person)article.Author).Name = "No one"; memento.Rollback(); Assert.AreEqual("DCastro", ((Person)article.Author).Name); }
public void Test() { Author author = new Author { Name = "DCastro" }; Article article = new Article { Author = author }; var memento = Memento.Create() .RegisterProperty(article, a => a.Author.Name); article.Author = new Author { Name = "No one" }; memento.Rollback(); Assert.AreEqual("DCastro", article.Author.Name); }
public void Test() { var article = new Article { Ids = null }; var memento = Memento.Create() .Register(article); article.Ids = new List <int> { 1 }; memento.Rollback(); CollectionAssert.AreEqual(new List <int> { 1 }, article.Ids); }
public void Test() { Article article = new Article { Pages = new Queue <int>( new[] { 1, 2, 3 }) }; //Act var memento = Memento.Create() .Register(article); article.Pages.Dequeue(); article.Pages.Dequeue(); memento.Rollback(); //Assert CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, article.Pages); }
public void TestWithMementoCollectionAttribute() { var author = new Author { Name = "DCastro" }; var article = new Article2 { Authors = new List <Author> { author } }; var memento = Memento.Create() .Register(article); author.Name = "No one"; memento.Rollback(); Assert.AreEqual("No one", article.Authors.First().Name); }
public void Test() { ConcreteArticle concreteArticle = new ConcreteArticle { Title = "Draft" }; AbstractArticle abstractArticle = new ConcreteArticle { Title = "Draft" }; var memento = Memento.Create() .RegisterProperty(concreteArticle, a => a.Title) .RegisterProperty(abstractArticle, a => a.Title); concreteArticle.Title = "Something else"; abstractArticle.Title = "Something else"; memento.Rollback(); Assert.AreEqual("Draft", concreteArticle.Title); Assert.AreEqual("Draft", abstractArticle.Title); }
public void WithMementoProperty() { var mainAuthor = new Author { Name = "DCastro" }; var article = new Article { MainAuthor = mainAuthor }; var memento = Memento.Create() .Register(article); mainAuthor.Name = "No one"; article.MainAuthor = new Author(); memento.Rollback(); Assert.AreSame(mainAuthor, article.MainAuthor); Assert.AreEqual("DCastro", mainAuthor.Name); }
public void Test() { Article article = new Article { Pages = new ConcurrentStack <int>( new[] { 1, 2, 3 }) }; //Act var memento = Memento.Create() .Register(article); int ignore; article.Pages.TryPop(out ignore); article.Pages.TryPop(out ignore); memento.Rollback(); //Assert CollectionAssert.AreEquivalent(new[] { 1, 2, 3 }, article.Pages); }
public void Test() { var author = new Author { Name = "DCastro" }; var article = new Article { Authors = new SimpleCollection <Author> { author } }; var memento = Memento.Create() .Register(article); author.Name = "No one"; memento.Rollback(); CollectionAssert.AreEqual("DCastro", article.Authors.First().Name); }
public void Test() { var article1 = new Article { Author = "DCastro" }; var article2 = new Article { Author = "JBarbosa" }; var articles = new Queue <Article>(new[] { article1, article2 }); var memento = Memento.Create() .RegisterCollection(new QueueAdapter <Article> { Collection = articles }); articles.Dequeue(); memento.Rollback(); Assert.AreEqual(2, articles.Count); CollectionAssert.Contains(articles, article1); CollectionAssert.Contains(articles, article2); }