public void As_By_T_Ask_Twice_For_Same_Property_First_Time_Goes_To_Database_Second_One_Found_On_Dictionary() { var setting1 = new Setting { EnvironmentName = "Application", Id = "CodeCityCrew.Settings.Test.MySetting", AssemblyName = "CodeCityCrew.Settings.Test", Value = "{\"ApplicationName\":\"\",\"CreatedDate\":\"9999-12-31T23:59:59.9999999\"}" }; MockSettingDbContext.SetupSequence(context => context.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development")) .Returns(() => setting1); var settingService = new SettingService(MockSettingDbContext.Object, MockIWebHostEnvironment.Object); //action var mySetting1 = settingService.As <MySetting>(); var mySetting2 = settingService.As <MySetting>(); Assert.NotNull(mySetting1); Assert.NotNull(mySetting2); MockSettingDbContext.Verify( context => context.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development"), Times.Once); MockSettingDbContext.Verify(context => context.Settings.Add(It.IsAny <Setting>()), Times.Never); MockSettingDbContext.Verify(context => context.SaveChanges(), Times.Never); }
public void As_By_T_Force_Reload() { var setting1 = new Setting { EnvironmentName = "Application", Id = "CodeCityCrew.Settings.Test.MySetting", AssemblyName = "CodeCityCrew.Settings.Test", Value = "{\"ApplicationName\":\"\",\"CreatedDate\":\"9999-12-31T23:59:59.9999999\"}" }; var setting2 = new Setting { EnvironmentName = "Application", Id = "CodeCityCrew.Settings.Test.MySetting", AssemblyName = "CodeCityCrew.Settings.Test", Value = "{\"ApplicationName\":\"Application\",\"CreatedDate\":\"9999-12-31T23:59:59.9999999\"}" }; MockSettingDbContext.SetupSequence(context => context.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development")) .Returns(() => setting1).Returns(setting2); var settingService = new SettingService(MockSettingDbContext.Object, MockIWebHostEnvironment.Object); //action var mySetting1 = settingService.As <MySetting>(); Assert.AreEqual(string.Empty, mySetting1.ApplicationName); Assert.AreEqual(DateTime.MaxValue, mySetting1.CreatedDate); Assert.NotNull(mySetting1); var mySetting2 = settingService.As <MySetting>(true); Assert.AreEqual("Application", mySetting2.ApplicationName); Assert.AreEqual(DateTime.MaxValue, mySetting2.CreatedDate); Assert.NotNull(mySetting2); MockSettingDbContext.Verify( context => context.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development"), Times.Exactly(2)); MockSettingDbContext.Verify(context => context.Settings.Add(It.IsAny <Setting>()), Times.Never); MockSettingDbContext.Verify(context => context.SaveChanges(), Times.Never); }
public void As_By_T_Is_Not_Found_In_Dictionary_Retrieve_From_Database() { MockSettingDbContext.Setup(context => context.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development")) .Returns(() => new Setting { EnvironmentName = "Application", Id = "CodeCityCrew.Settings.Test.MySetting", AssemblyName = "CodeCityCrew.Settings.Test", Value = "{\"ApplicationName\":\"Application\",\"CreatedDate\":\"9999-12-31T23:59:59.9999999\"}" }); var settingService = new SettingService(MockSettingDbContext.Object, MockIWebHostEnvironment.Object); //action var mySetting = settingService.As <MySetting>(); MockSettingDbContext.Verify( context => context.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development"), Times.Once); MockSettingDbContext.Verify(context => context.Settings.Add(It.IsAny <Setting>()), Times.Never); MockSettingDbContext.Verify(context => context.SaveChanges(), Times.Never); Assert.NotNull(mySetting); Assert.AreEqual("Application", mySetting.ApplicationName); Assert.AreEqual(DateTime.MaxValue, mySetting.CreatedDate); }
public void Should_return_object() { // creates new entry var setting = SettingService.As <MySetting>(); Assert.NotNull(setting); }
public void Should_return_null() { SettingService.Save((MySetting)null); var mySetting = SettingService.As <MySetting>(); Assert.IsNull(mySetting); }
public void As_By_Namespace_Not_Found_In_Database() { MockSettingDbContext.Setup(context => context.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development")) .Returns(() => null); var settingService = new SettingService(MockSettingDbContext.Object, MockIWebHostEnvironment.Object); var setting = settingService.As("CodeCityCrew.Settings.Test.MySetting") as MySetting; Assert.NotNull(setting); Assert.AreEqual("Application", setting.ApplicationName); Assert.AreEqual(DateTime.MaxValue, setting.CreatedDate); }
public void Accessing_same_setting_twice() { // creates new entry var setting = SettingService.As <MySetting>(); setting.ApplicationName = "NewName"; SettingService.Save(setting); var find = SettingDbContext.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development"); Assert.IsNotNull(find); // get from dictionary. var mySetting1 = SettingService.As <MySetting>(); Assert.AreEqual("NewName", mySetting1.ApplicationName); }
public void As_By_T_Not_Found() { MockSettingDbContext.Setup(context => context.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development")) .Returns(() => null); var settingService = new SettingService(MockSettingDbContext.Object, MockIWebHostEnvironment.Object); var mySetting = settingService.As <MySetting>(); MockSettingDbContext.Verify( context => context.Settings.Find("CodeCityCrew.Settings.Test.MySetting", "Development"), Times.Once); MockSettingDbContext.Verify(context => context.Settings.Add(It.IsAny <Setting>()), Times.Once); MockSettingDbContext.Verify(context => context.SaveChanges(), Times.Once); Assert.NotNull(mySetting); Assert.AreEqual("Application", mySetting.ApplicationName); Assert.AreEqual(DateTime.MaxValue, mySetting.CreatedDate); }