Exemplo n.º 1
0
        public void Get_ById_Test()
        {
            Mock <BaseStartupDemo> mockedContext = new Mock <BaseStartupDemo>();

            mockedContext.Object.Configurations = LoadMockedUsers();

            ConfigurationsRepository repo = new ConfigurationsRepository(mockedContext.Object, true);

            var result = repo.Get(1);

            Assert.AreEqual <int>(1, result.ID);
        }
Exemplo n.º 2
0
        public void Delete_Test()
        {
            Mock <BaseStartupDemo> mockedContext = new Mock <BaseStartupDemo>();

            mockedContext.Object.Configurations = LoadMockedUsers();

            ConfigurationsRepository repo = new ConfigurationsRepository(mockedContext.Object, false);

            repo.Delete(1);

            DtoConfiguration deleted = (from u in mockedContext.Object.Configurations where u.ID == 1 select u).FirstOrDefault();

            Assert.IsNull(deleted);
        }
Exemplo n.º 3
0
        public void Add_Test()
        {
            Mock <BaseStartupDemo> mockedContext = new Mock <BaseStartupDemo>();

            mockedContext.Object.Configurations = LoadMockedUsers();

            ConfigurationsRepository repo = new ConfigurationsRepository(mockedContext.Object, false);

            repo.Add(new DtoConfiguration(0, "New Config", "New Value"));

            DtoConfiguration added = (from u in mockedContext.Object.Configurations where u.Name == "New Config" select u).FirstOrDefault();

            Assert.IsNotNull(added);
        }
Exemplo n.º 4
0
        public void Update_Test()
        {
            Mock <BaseStartupDemo> mockedContext = new Mock <BaseStartupDemo>();

            mockedContext.Object.Configurations = LoadMockedUsers();

            ConfigurationsRepository repo = new ConfigurationsRepository(mockedContext.Object, false);

            repo.Update(new DtoConfiguration(1, "Updated Config", "Updated Config Value"));

            DtoConfiguration updated = (from u in mockedContext.Object.Configurations where u.ID == 1 select u).FirstOrDefault();

            Assert.AreEqual <string>("Updated Config", updated.Name);
            Assert.AreEqual <string>("Updated Config Value", updated.Value);
        }
Exemplo n.º 5
0
        public void Add_In_ReadOnly_Test()
        {
            Mock <BaseStartupDemo> mockedContext = new Mock <BaseStartupDemo>();

            mockedContext.Object.Configurations = LoadMockedUsers();

            ConfigurationsRepository repo = new ConfigurationsRepository(mockedContext.Object, true);
            Exception expected_ex         = null;

            try
            {
                repo.Add(new DtoConfiguration(0, "New Config", "New Value"));
            }
            catch (ReadOnlyException ex) { expected_ex = ex; }

            Assert.IsNotNull(expected_ex);
        }