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