public void SetUp()
        {
            this.repository = new FakeRepository();
            this.identity   = new FakeIdentity();
            var comment = new Comment {
                Content = "content"
            };
            var trash = new Trash {
                Id = 1, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>()
                {
                    comment
                }
            };
            var trash2 = new Trash {
                Id = 2, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>()
                {
                    comment
                }
            };
            var trash3 = new Trash {
                Id = 3, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>()
                {
                    comment
                }
            };

            this.repository.Add(trash);
            this.repository.Add(trash2);
            this.repository.Add(trash3);
            this.controller = new TrashesController(this.repository, this.identity);
        }
Esempio n. 2
0
        public void SetUp()
        {
            var comment = new Comment {
                Content = "content"
            };
            var trashes = new List <Trash>
            {
                new Trash {
                    Id = 1, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>()
                    {
                        comment
                    }
                },
                new Trash {
                    Id = 2, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>()
                    {
                        comment
                    }
                },
                new Trash {
                    Id = 3, Title = "Title", AddTime = DateTime.Now, Content = "content", Comments = new List <Comment>()
                    {
                        comment
                    }
                }
            };
            var repositoryMock = new Mock <IRepository>();

            repositoryMock.Setup(x => x.Trash).Returns(trashes.AsQueryable());
            repositoryMock.Setup(x => x.Add(It.IsAny <Trash>())).Callback((object trash) => trashes.Add(trash as Trash));
            repositoryMock.Setup(x => x.Remove(It.IsAny <Trash>())).Callback((object trash) => trashes.Remove(trash as Trash));
            repositoryMock.Setup(x => x.Edit(It.IsAny <Trash>())).Callback((object trash) => trashes[trashes.IndexOf(trashes.First(x => x.Id == (trash as Trash).Id))] = trash as Trash);
            this.repository = repositoryMock.Object;

            var identityMock = new Mock <IControllerIdentity>();

            identityMock.Setup(x => x.Name).Returns("Name");
            identityMock.Setup(x => x.AuthenticationType).Returns("Type");
            identityMock.Setup(x => x.IsAuthenticated).Returns(true);
            identityMock.Setup(x => x.GetUserId()).Returns("1");
            identityMock.Setup(x => x.GetUserName()).Returns("Name");
            this.identity   = identityMock.Object;
            this.controller = new TrashesController(this.repository, this.identity);
        }