public void Save() { var testClass = new CustomIdStringClass(); Assert.Throws <InvalidIdException>(() => testClass.Save()); var id = Guid.NewGuid().ToString(); testClass.CustomId = id; testClass.Save(); Assert.False(testClass.IsNew()); Assert.False(testClass.IsModified()); Assert.True(id == testClass.Id()); Assert.Equal(id, testClass.CustomId); var loadedTestClass = Modl <CustomIdStringClass> .Get(id); Assert.Equal(id, loadedTestClass.CustomId); Assert.True(id == loadedTestClass.Id()); Assert.Equal(id, loadedTestClass.CustomId); Assert.False(loadedTestClass.IsNew()); Assert.False(loadedTestClass.IsModified()); Assert.Throws <InvalidIdException>(() => loadedTestClass.Id(Guid.NewGuid().ToString())); Assert.Throws <InvalidIdException>(() => { loadedTestClass.CustomId = Guid.NewGuid().ToString(); loadedTestClass.Save(); }); }
public void List() { var modl = new CustomIdStringClass().Id(Guid.NewGuid().ToString()).Save(); var modl2 = new CustomIdStringClass().Id(Guid.NewGuid().ToString()).Save(); var modlList = Modl <CustomIdStringClass> .List().ToList(); Assert.NotEqual(0, modlList.Count); Assert.True(modlList.Any(x => x as string == modl.Id().Get <string>())); Assert.True(modlList.Any(x => x as string == modl2.Id().Get <string>())); var modlList2 = Modl <CustomIdStringClass> .List <string>().ToList(); Assert.NotEqual(0, modlList2.Count); Assert.True(modlList2.Any(x => x == modl.Id().Get <string>())); Assert.True(modlList2.Any(x => x == modl2.Id().Get <string>())); }
public void SetId() { var id = Guid.NewGuid().ToString(); var testClass = new CustomIdStringClass(); Assert.Equal(null, testClass.CustomId); Assert.False(testClass.Id().IsSet); testClass.Id(id); Assert.True(testClass.Id().IsSet); Assert.True(id == testClass.Id()); Assert.True(testClass.IsNew()); Assert.False(testClass.IsModified()); Assert.Equal(id, testClass.CustomId); id = Guid.NewGuid().ToString(); testClass = new CustomIdStringClass(); Assert.Equal(null, testClass.CustomId); Assert.False(testClass.Id().IsSet); testClass.CustomId = id; Assert.True(testClass.Id().IsSet); Assert.Equal(id, testClass.Id().Get()); Assert.True(testClass.IsNew()); Assert.False(testClass.IsModified()); Assert.Equal(id, testClass.CustomId); try { testClass.Id(Guid.NewGuid()); //Assert.Fail(); } catch (InvalidIdException) { } try { testClass.Id(1); } catch (InvalidIdException) { } }
public void CreateNew() { var testClass = new CustomIdStringClass(); Assert.True(testClass.IsNew()); Assert.False(testClass.IsModified()); testClass = Modl<CustomIdStringClass>.New(); Assert.True(testClass.IsNew()); Assert.False(testClass.IsModified()); var id = Guid.NewGuid().ToString(); testClass = Modl<CustomIdStringClass>.New(id); Assert.True(testClass.IsNew()); Assert.False(testClass.IsModified()); Assert.True(id == testClass.Id()); Assert.Equal(id, testClass.CustomId); }
public void GetAll() { foreach (var m in Modl <CustomIdStringClass> .GetAll()) { m.Delete(); } var modlList = Modl <CustomIdStringClass> .GetAll().ToList(); Assert.Equal(0, modlList.Count); var modl = new CustomIdStringClass().Id(Guid.NewGuid().ToString()).Save(); var modl2 = new CustomIdStringClass().Id(Guid.NewGuid().ToString()).Save(); modlList = Modl <CustomIdStringClass> .GetAll().ToList(); Assert.Equal(2, modlList.Count); Assert.True(modlList.Any(x => x.Id() == modl.Id())); Assert.True(modlList.Any(x => x.Id() == modl2.Id())); }
public void CreateNew() { var testClass = new CustomIdStringClass(); Assert.True(testClass.IsNew()); Assert.False(testClass.IsModified()); testClass = Modl <CustomIdStringClass> .New(); Assert.True(testClass.IsNew()); Assert.False(testClass.IsModified()); var id = Guid.NewGuid().ToString(); testClass = Modl <CustomIdStringClass> .New(id); Assert.True(testClass.IsNew()); Assert.False(testClass.IsModified()); Assert.True(id == testClass.Id()); Assert.Equal(id, testClass.CustomId); }
public void List() { var modl = new CustomIdStringClass().Id(Guid.NewGuid().ToString()).Save(); var modl2 = new CustomIdStringClass().Id(Guid.NewGuid().ToString()).Save(); var modlList = Modl<CustomIdStringClass>.List().ToList(); Assert.NotEqual(0, modlList.Count); Assert.True(modlList.Any(x => x as string == modl.Id().Get<string>())); Assert.True(modlList.Any(x => x as string == modl2.Id().Get<string>())); var modlList2 = Modl<CustomIdStringClass>.List<string>().ToList(); Assert.NotEqual(0, modlList2.Count); Assert.True(modlList2.Any(x => x == modl.Id().Get<string>())); Assert.True(modlList2.Any(x => x == modl2.Id().Get<string>())); }
public void GetAll() { foreach (var m in Modl<CustomIdStringClass>.GetAll()) m.Delete(); var modlList = Modl<CustomIdStringClass>.GetAll().ToList(); Assert.Equal(0, modlList.Count); var modl = new CustomIdStringClass().Id(Guid.NewGuid().ToString()).Save(); var modl2 = new CustomIdStringClass().Id(Guid.NewGuid().ToString()).Save(); modlList = Modl<CustomIdStringClass>.GetAll().ToList(); Assert.Equal(2, modlList.Count); Assert.True(modlList.Any(x => x.Id() == modl.Id())); Assert.True(modlList.Any(x => x.Id() == modl2.Id())); }
public void Save() { var testClass = new CustomIdStringClass(); Assert.Throws<InvalidIdException>(() => testClass.Save()); var id = Guid.NewGuid().ToString(); testClass.CustomId = id; testClass.Save(); Assert.False(testClass.IsNew()); Assert.False(testClass.IsModified()); Assert.True(id == testClass.Id()); Assert.Equal(id, testClass.CustomId); var loadedTestClass = Modl<CustomIdStringClass>.Get(id); Assert.Equal(id, loadedTestClass.CustomId); Assert.True(id == loadedTestClass.Id()); Assert.Equal(id, loadedTestClass.CustomId); Assert.False(loadedTestClass.IsNew()); Assert.False(loadedTestClass.IsModified()); Assert.Throws<InvalidIdException>(() => loadedTestClass.Id(Guid.NewGuid().ToString())); Assert.Throws<InvalidIdException>(() => { loadedTestClass.CustomId = Guid.NewGuid().ToString(); loadedTestClass.Save(); }); }