Example #1
0
        public void CanEditContact()
        {
            MockRepository         mock        = new MockRepository();
            IDistributorRepository mockedRepos = mock.CreateMock <IDistributorRepository>();

            Contact contact = new Contact("Gali", "Emi", "*****@*****.**");

            Expect.Call(mockedRepos.GetContactById(1)).Return(contact);
            Expect.Call(mockedRepos.SaveContact(contact)).Return(contact);
            mockedRepos.CommitChanges();
            LastCall.On(mockedRepos);
            mock.ReplayAll();
            DistributorController dc = new DistributorController(mockedRepos);

            Contact c = dc.EditContact(1, "Emi Cambiado", "Gali cambiado", "*****@*****.**");

            Assert.AreNotEqual("Emi", c.Name);
            Assert.AreEqual("Gali cambiado", c.LastName);
            Assert.AreNotEqual("*****@*****.**", c.Email);
        }
Example #2
0
        public void CanChangeContactStatus()
        {
            MockRepository         mock        = new MockRepository();
            IDistributorRepository mockedRepos = mock.CreateMock <IDistributorRepository>();

            Contact contact = new Contact("Gali", "Emi", "*****@*****.**");

            Expect.Call(mockedRepos.GetContactById(1)).Return(contact);
            Expect.Call(mockedRepos.SaveContact(contact)).Return(contact);
            //Para los metodos de tipo de void se llama al metodo desde el repositorio directamente
            //y si o si se debe hacer un LastCall para todo el repositorio MOCK
            mockedRepos.CommitChanges();
            LastCall.On(mockedRepos);
            mock.ReplayAll();
            DistributorController dc = new DistributorController(mockedRepos);

            Contact test = dc.GetContactById(1);

            test = dc.ChangeContactStatus(test);

            Assert.AreEqual(test.Status, ContactStatus.Disable);
        }