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); }
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); }
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); }
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); }
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); }