public void GenericTools_Singleton_Class() { var a = SampleModelSingleton.Instance; var b = SampleModelSingleton.Instance; MakeSure.That(a).Is(b); }
public void Logger_Create_Object() { using (var logger = new Logger()) { MakeSure.That(logger).IsNot(null); } }
public void GenericTools_RepositoryHandler_AddUpdateDelete() { //register sample service RepositoryHandler.Add(new SampleModelRepository()); var item = RepositoryHandler.Get <SampleModelRepository>().Add(new SampleModel() { Age = 50 }); MakeSure.That(item.Age).Is(50); MakeSure.That(RepositoryHandler.Get <SampleModelRepository>().Get(i => i == item)).Is(item); MakeSure.That(RepositoryHandler.Get <SampleModelRepository>().Count).Is(4); var newItem = RepositoryHandler.Get <SampleModelRepository>().Update(item, new SampleModel() { Age = 53 }); MakeSure.That(RepositoryHandler.Get <SampleModelRepository>().Get(i => i == newItem)).Is(newItem); MakeSure.That(RepositoryHandler.Get <SampleModelRepository>().Count).Is(4); RepositoryHandler.Get <SampleModelRepository>().Delete(i => i.Age > 40); MakeSure.That(RepositoryHandler.Get <SampleModelRepository>().Count).Is(3); MakeSure.That(() => RepositoryHandler.Get <SampleModelRepository>().SaveChanges()).DoesNotThrow(); }
public void WebService_Handler_HandleNull() { var response = WebServiceHandler.Handle <SampleModel>(GetDataException); MakeSure.That(response.Status).Is(StatusCode.Error); MakeSure.That(response.Error).Is("Test"); }
public void Config_LoadFrom_ConfigManager() { //load the app config file var cfg = Config.Create(); MakeSure.That(cfg.Count).IsGreaterThan(0); }
public void Generic_UpdateList_Predicate_Class() { var models = new List <SampleModel> { new SampleModel() { Age = 23 }, new SampleModel() { Age = 12 }, new SampleModel() { Age = 33 } }; MakeSure.That(() => models.FirstOrDefault(i => i.Age == 34).Safe()).Throws <ArgumentNullException>(); models.ForEach(i => MakeSure.That(i.Type).Is(ModelType.Sample)); var x = GetModel().ThrowIfNull("model").And().IfNotNull(model => model.Age = 23); var y = GetModelNull().IfNull(model => new SampleModel() { Age = 17 }); MakeSure.That(x.Age).Is(23); MakeSure.That(y.Age).Is(17); }
public void Workflow_Multiple_Action() { var counterA = 0; var counterB = 10; var counterC = 0; var workflow = new Workflow( new Step(() => counterA++), new Step(() => counterB--), new Step(() => { throw new Exception("should fail"); }), new Step(() => counterC++) //should not be executed ); var result = Engine.Start(workflow); MakeSure.That(result).IsNot(null); MakeSure.That(result.CompletedSteps.Count).Is(2); MakeSure.That(result.FailedSteps.Count).Is(1); MakeSure.That(result.HasErrors).Is(true); MakeSure.That(result.Exception).IsNot(null); MakeSure.That(result.Exception.Message).Is("should fail"); MakeSure.That(counterA).Is(1); MakeSure.That(counterB).Is(9); MakeSure.That(counterC).Is(0); }
public void Generic_IfNull_IfNotNull_Chaining() { //just check if not null MakeSure.That(GetModel().IfNotNull(() => Assert.IsTrue(true)).Age).Is(22); //reset the age MakeSure.That(GetModel().IfNotNull(() => new SampleModel() { Age = 27 }).Age).Is(27); //check for null MakeSure.That(GetModelNull().IfNull(() => MakeSure.That(true).Is(true))).Is(null); //create new object when null MakeSure.That(GetModelNull().IfNull(() => new SampleModel() { Age = 27 }).Age).Is(27); //create ne wobject and check directly GetModelNull().IfNull(() => new SampleModel()).And().IfNotNull(model => MakeSure.That(model).IsNot(null)); MakeSure.That(() => GetModel() .IfNotNull(() => null) .And() .IfNull(model => Assert.IsNull(model)) .And() .ThrowIfNull("model")) .Throws <ArgumentNullException>(); }
public void Date_Yesterday_Tomorrow() { var today = DateTime.Now.Date; MakeSure.That(today.Yesterday()).Is(today.AddDays(-1)); MakeSure.That(today.Tomorrow()).Is(today.AddDays(1)); }
public void Aggregator_Add_Subscription() { var aggregator = new Aggregator(); aggregator.Subscribe <SampleAddEvent>(@event => { }); MakeSure.That(aggregator.IsSubscribed <SampleAddEvent>()).Is(true); }
public void GenericTools_Singleton() { var a = Singleton <SampleModel> .Instance; var b = Singleton <SampleModel> .Instance; MakeSure.That(a).Is(b); }
public void ViewEngine_Dynamic_SingleSubstitutions() { //strings and simple types MakeSure.That(ViewEngine.Instance.Render("Hello @Model", "World")).Is("Hello World"); MakeSure.That(ViewEngine.Instance.Render("Hello @Model", 1)).Is("Hello 1"); MakeSure.That(ViewEngine.Instance.Render("Hello @Model", DateTime.Now.ToShortTimeString())).Is("Hello {0}".With(DateTime.Now.ToShortTimeString())); dynamic basic = new ExpandoObject(); basic.Name = "World"; dynamic extended = new ExpandoObject(); extended.Data = new ExpandoObject(); extended.Data = "World"; var real = new SampleModel { Age = 38, Title = "Model", Type = ModelType.Example }; //object MakeSure.That(ViewEngine.Instance.Render("Hello @Model.Data", extended)).Is("Hello World"); MakeSure.That(ViewEngine.Instance.Render("Hello @Model.Age", real)).Is("Hello 38"); MakeSure.That(ViewEngine.Instance.Render("Hello @Model.Type", real)).Is("Hello Example"); //extensions var renderable = new RenderableModel { Title = "Cool" }; MakeSure.That(renderable.Render("Hello @Model.Title")).Is("Hello Cool"); MakeSure.That("Hello @Model.Title".RenderWith(renderable)).Is("Hello Cool"); }
public void Generics_In_List() { var numbers = new[] { 1, 2, 3, 4, 5 }; MakeSure.That(3.In(numbers)).Is(true); MakeSure.That(new[] { 3, 5 }.In(numbers)).Is(true); MakeSure.That(new[] { 7, 1 }.In(numbers)).Is(false); }
public void WebService_Handler_HandleSample() { var response = WebServiceHandler.Handle(GetData); MakeSure.That(response.Status).Is(StatusCode.Ok); MakeSure.That(response.Error).Is(null); MakeSure.That(response.Result.Age).Is(23); }
public void Generic_And_ListAdd() { var models = new List <SampleModel>() .And(l => l.Add(new SampleModel())) .And(l => l.Add(new SampleModel())); MakeSure.That(models.Count).Is(2); }
public void ViewEngine_Dynamic_Conditionals() { var m1 = new RenderableModel { HasUsers = true, HasAdmins = false, Title = "Cool" }; MakeSure.That(m1.Render("@If.HasUsers @Model.Title @EndIf @IfNot.HasAdmins no admins! @EndIf")).Is("Cool no admins!"); }
public void String_IsMatch_Regex() { const string sampleText = "sample 33 xxx 322"; MakeSure.That(sampleText.Matches(@"\d+")).Is(true); sampleText.Matches(@"\d+", () => MakeSure.That(true).Is(true)); }
public void Wpf_Converters_BooleanToVisibility() { var converter = new BooleanToVisibilityConverter(); MakeSure.That(converter.Convert(true, null)).Is(Visibility.Visible); MakeSure.That(converter.Convert(false, null)).Is(Visibility.Collapsed); MakeSure.That(converter.Convert(false, "i")).Is(Visibility.Visible); MakeSure.That(converter.Convert(true, "i")).Is(Visibility.Collapsed); }
public void Wpf_RelayCommands() { var count = 0; var command = new RelayCommand(o => count++, o => o.IsNotNull()); MakeSure.That(command.CanExecute(count)).Is(true); command.Execute(count); MakeSure.That(count).Is(1); }
public void Generic_RemoveFromList_Predicate() { var numbers = new List <int> { 1, 3, 5, 7, 9 }; numbers.Remove(i => i == 7); MakeSure.That(numbers.Contains(7)).Is(false); }
public void Object_Is_Comparisons() { MakeSure.That(3.Is < int > ()).Is(true); var e = new SampleAddEvent(); MakeSure.That(e.Is <SampleAddEvent>()).Is(true); e.Data.IfNull(() => MakeSure.That(true).Is(true)); }
public void Aggregator_Add_SubscriptionAndPublish() { var aggregator = new Aggregator(); aggregator.Subscribe <SampleAddEvent>(e => MakeSure.That(Convert.ToInt32(e.Data)).Is(3)); aggregator.Publish(new SampleAddEvent { Data = 3 }); }
public void Logger_Create_FileLogger() { const string path = @"log.txt"; TestLogger(new FileLogger(path)); MakeSure.That(File.Exists(path)).Is(true); File.Delete(path); }
public void GenericTools_Data_Mapping() { //maps the SampleModelDto to a new HomeModel using JSON serialization var result = Mapper.Map <SampleModelDto, HomeModel>(new SampleModelDto { Title = "test" }); MakeSure.That(result.Title).Is("test"); }
public void Generic_Delegate_Extensions() { var counter = 0; //execute it 5 times... new Action(() => counter++).Execute(5).Times(); MakeSure.That(counter).Is(5); }
public void Config_GetAndSet_NotFound() { const int expected = 3; var config = new Config(); config.Set(new ConfigEntry("MyKey", expected)); MakeSure.That(() => config.Get <int>("MyKey1")).Throws <ArgumentNullException>(); }
public void GenericTools_Data_MemoryDatabase_int() { var db = new MemoryDatabase <int>(); db.Add(3); db.Add(7); db.Add(5); MakeSure.That(db.GetAll().Sum(i => i)).Is(15); }
public void Config_GetAndSet_Simple() { const int expected = 3; var config = new Config(); config.Set(new ConfigEntry("MyKey", expected)); MakeSure.That(config.Get <int>("MyKey")).Is(expected); MakeSure.That(config["MyKey"].As <int>()).Is(expected); }
public void GenericTools_Data_MemorySession() { using (var session = new MemorySession()) { var db = session.Database <SampleModel>(); db.Add(new SampleModel()); var db2 = session.Database <SampleModel>(); MakeSure.That(db2.Count).Is(1); } }
public void GenericTools_Collection_DataStore() { var store = new DataStore() .Set("test", 3) .Set("test2", new SampleModel()) .Set("test3", "bla"); MakeSure.That(store.Get <int>("test")).Is(3); MakeSure.That(store.Get <SampleModel>("test2").GetType()).Is(typeof(SampleModel)); MakeSure.That(store.Get <string>("test3")).Is("bla"); }