public void TestMergeUpdatingRemoteId() { var remoteId1 = 1234; var remoteId2 = 4321; PlainModel storedModel = null; ServiceContainer.Register(Mock.Of <IModelStore> ( store => store.GetByRemoteId <PlainModel> (remoteId1) == storedModel && store.GetByRemoteId(typeof(PlainModel), remoteId1) == storedModel && store.GetByRemoteId <PlainModel> (remoteId2) == storedModel && store.GetByRemoteId(typeof(PlainModel), remoteId2) == storedModel )); var model = Manager.Update(new PlainModel() { RemoteId = remoteId1, ModifiedAt = new DateTime(), }); Assert.AreSame(model, Manager.GetByRemoteId <PlainModel> (remoteId1)); Assert.IsNull(Manager.GetByRemoteId <PlainModel> (remoteId2)); model.Merge(new PlainModel() { RemoteId = remoteId2, ModifiedAt = Time.UtcNow, }); Assert.AreEqual(remoteId2, model.RemoteId, "Model remote id was not updated by merge."); Assert.IsNull(Manager.GetByRemoteId <PlainModel> (remoteId1), "Manager still returns model by old remote id."); Assert.AreSame(model, Manager.GetByRemoteId <PlainModel> (remoteId2), "Unable to find model by remote id after merge."); }
public void TestMakeShared() { // Verify the ModelChangedMessage send count var messageCount = 0; MessageBus.Subscribe <ModelChangedMessage> ((msg) => { messageCount++; }); var model = new PlainModel(); model.PropertyChanged += (sender, e) => { if (e.PropertyName == PlainModel.PropertyIsShared) { // Check that model is present in cache Assert.That(Model.Manager.Cached <PlainModel> (), Has.Exactly(1).SameAs(model), "The newly shared object should be present in cache already."); } else if (e.PropertyName == PlainModel.PropertyId) { // Expect ID assignment } else { Assert.Fail(String.Format("Property '{0}' changed unexpectedly.", e.PropertyName)); } }; var shared = Model.Update(model); Assert.AreSame(model, shared, "Promoting to shared should return the initial model."); Assert.NotNull(model.Id, "Should have received a new unique Id."); Assert.AreEqual(messageCount, 1, "Received invalid number of OnModelChanged messages"); }
public void TestMakeShared () { // Verify the ModelChangedMessage send count var messageCount = 0; MessageBus.Subscribe<ModelChangedMessage> ((msg) => { messageCount++; }); var model = new PlainModel (); model.PropertyChanged += (sender, e) => { if (e.PropertyName == PlainModel.PropertyIsShared) { // Check that model is present in cache Assert.That (Model.Manager.Cached<PlainModel> (), Has.Exactly (1).SameAs (model), "The newly shared object should be present in cache already."); } else if (e.PropertyName == PlainModel.PropertyId) { // Expect ID assignment } else { Assert.Fail (String.Format ("Property '{0}' changed unexpectedly.", e.PropertyName)); } }; var shared = Model.Update (model); Assert.AreSame (model, shared, "Promoting to shared should return the initial model."); Assert.NotNull (model.Id, "Should have received a new unique Id."); Assert.AreEqual (messageCount, 1, "Received invalid number of OnModelChanged messages"); }
public PlainModel UpdatePlainModel([FromBody] PlainModel model) { if (ModelState.IsValid) { model = this._repository.Update(model); } return(model); }
internal PlainModel ConvertToPlainModel() { PlainModel plain = new PlainModel(); plain.Flights = Flights; plain.Id = Id; plain.Name = Name; plain.Sits = Sits; return(plain); }
//[Route("{controller}/index/{id?}")] public string Index() { PlainModel model = new PlainModel() { Company = "AppleIndex", Employees = 1000000, Salary = 400000 }; return($"Company: {model.Company}\nEmployees: {model.Employees}\nSalary: {model.Salary}\n"); }
public string Home1() { PlainModel model = new PlainModel() { Company = "AppleIndex1", Employees = 2000000, Salary = 800000 }; return($"Company: {model.Company}\nEmployees: {model.Employees}\nSalary: {model.Salary}\n"); }
public void TestGetByIdNotFound() { var id = Guid.NewGuid(); PlainModel storedModel = null; ServiceContainer.Register(Mock.Of <IModelStore> ( store => store.Get <PlainModel> (id) == storedModel && store.Get(typeof(PlainModel), id) == storedModel )); Assert.IsNull(Manager.Get <PlainModel> (id)); }
public void TestGetByRemoteIdNotFound() { var remoteId = 1234; PlainModel storedModel = null; ServiceContainer.Register(Mock.Of <IModelStore> ( store => store.GetByRemoteId <PlainModel> (remoteId) == storedModel && store.GetByRemoteId(typeof(PlainModel), remoteId) == storedModel )); Assert.IsNull(Manager.GetByRemoteId <PlainModel> (remoteId)); }
private PlainModel GetNewPlain() { char firstLatter = (char)rnd.Next(65, 90); char secondLatter = (char)rnd.Next(65, 90); string number = rnd.Next(100, 999).ToString(); PlainModel newPlain = new PlainModel() { Name = firstLatter + secondLatter + number, Sits = rnd.Next(150, 1000) }; return(newPlain); }
public void TestDefaults() { var model = new PlainModel(); Assert.IsNull(model.Id, "Id must be null"); Assert.IsNull(model.RemoteId, "RemoteId must be null"); Assert.IsFalse(model.IsShared, "IsShared must be false"); Assert.IsFalse(model.IsPersisted, "IsPersisted must be false"); Assert.That(model.ModifiedAt, Is.EqualTo(Time.UtcNow).Within(1).Seconds, "ModifiedAt must be the time of model creation"); Assert.IsFalse(model.IsDirty, "IsDirty must be false"); Assert.IsFalse(model.IsMerging, "IsMerging must be false"); Assert.IsNull(model.DeletedAt, "DeletedAt must be null"); Assert.IsNull(model.RemoteDeletedAt, "RemoteDeletedAt must be null"); }
public void TestDefaults () { var model = new PlainModel (); Assert.IsNull (model.Id, "Id must be null"); Assert.IsNull (model.RemoteId, "RemoteId must be null"); Assert.IsFalse (model.IsShared, "IsShared must be false"); Assert.IsFalse (model.IsPersisted, "IsPersisted must be false"); Assert.That (model.ModifiedAt, Is.EqualTo (Time.UtcNow).Within (1).Seconds, "ModifiedAt must be the time of model creation"); Assert.IsFalse (model.IsDirty, "IsDirty must be false"); Assert.IsFalse (model.IsMerging, "IsMerging must be false"); Assert.IsNull (model.DeletedAt, "DeletedAt must be null"); Assert.IsNull (model.RemoteDeletedAt, "RemoteDeletedAt must be null"); }
public void TestGetByIdFromStore () { var id = Guid.NewGuid (); var storedModel = new PlainModel () { Id = id, }; ServiceContainer.Register (Mock.Of<IModelStore> ( store => store.Get<PlainModel> (id) == storedModel && store.Get (typeof(PlainModel), id) == storedModel )); Assert.AreSame (storedModel, Manager.Get<PlainModel> (id)); }
public IActionResult Index() { PlainModel model = new PlainModel() { Company = "Microsoft", Employees = 100000, Salary = 10000 }; ViewData["totalSalary"] = model.Employees * model.Salary; ViewData["company"] = model.Company; ViewData["employees"] = model.Employees; return(View()); }
public FlightModel CreateFlight() { string flightName = GetName(); PlainModel plain = GetNewPlain(); bool isDeparture = GetIsDeparture(); DateTime planedTime = GetPlanedTime(); return(new FlightModel() { FlightName = flightName, IsDeparture = isDeparture, Plain = plain, Time = planedTime }); }
public void TestGetByIdFromStore() { var id = Guid.NewGuid(); var storedModel = new PlainModel() { Id = id, }; ServiceContainer.Register(Mock.Of <IModelStore> ( store => store.Get <PlainModel> (id) == storedModel && store.Get(typeof(PlainModel), id) == storedModel )); Assert.AreSame(storedModel, Manager.Get <PlainModel> (id)); }
public void TestGetByRemoteIdFromStore () { var remoteId = 1234; var storedModel = new PlainModel () { Id = Guid.NewGuid (), RemoteId = remoteId, }; ServiceContainer.Register (Mock.Of<IModelStore> ( store => store.GetByRemoteId<PlainModel> (remoteId) == storedModel && store.GetByRemoteId (typeof(PlainModel), remoteId) == storedModel )); Assert.AreSame (storedModel, Manager.GetByRemoteId<PlainModel> (remoteId)); }
//public string Index() //{ // ThickModel model = new ThickModel("CBS", 100, 6000); // int totalSalary = model.TotalSalary(); // string company = $"Company: {model.Company}\n"; // string empoyees = $"Employees: {model.Employees}\n"; // string salary = $"Total Salary: {totalSalary}\n"; // return company + empoyees + salary; //} public string Index() { PlainModel model = new PlainModel() { Company = "Microsoft", Employees = 100000, Salary = 10000 }; int totalSalary = model.Employees * model.Salary; string company = $"Company: {model.Company}\n"; string empoyees = $"Employees: {model.Employees}\n"; string salary = $"Total Salary: {totalSalary}\n"; return(company + empoyees + salary); }
public void TestGetByRemoteIdFromStore() { var remoteId = 1234; var storedModel = new PlainModel() { Id = Guid.NewGuid(), RemoteId = remoteId, }; ServiceContainer.Register(Mock.Of <IModelStore> ( store => store.GetByRemoteId <PlainModel> (remoteId) == storedModel && store.GetByRemoteId(typeof(PlainModel), remoteId) == storedModel )); Assert.AreSame(storedModel, Manager.GetByRemoteId <PlainModel> (remoteId)); }
public void TestGetByRemoteIdFromCache() { var remoteId = 1234; PlainModel storedModel = null; ServiceContainer.Register(Mock.Of <IModelStore> ( store => store.GetByRemoteId <PlainModel> (remoteId) == storedModel && store.GetByRemoteId(typeof(PlainModel), remoteId) == storedModel )); // TODO: Should instead just mock the cache var model = Manager.Update(new PlainModel() { RemoteId = remoteId, }); Assert.AreSame(model, Manager.GetByRemoteId <PlainModel> (remoteId)); }
public void TestGetByIdFromCache() { var id = Guid.NewGuid(); PlainModel storedModel = null; ServiceContainer.Register(Mock.Of <IModelStore> ( store => store.Get <PlainModel> (id) == storedModel && store.Get(typeof(PlainModel), id) == storedModel )); // TODO: Should instead just mock the cache var model = Manager.Update(new PlainModel() { Id = id, }); Assert.AreSame(model, Manager.Get <PlainModel> (id)); }
public IActionResult Index() { PlainModel plainModel = new PlainModel() { Company = "Apple", Employees = 1000000, Salary = 400000 }; ViewDataDictionary valuePairs = new ViewDataDictionary(ViewData); valuePairs.Add("Company", "Apple"); valuePairs.Add("Employees", "1000000"); valuePairs.Add("Salary", "400000"); valuePairs.Add("user", "password"); valuePairs.Add("count", valuePairs.Count); foreach (var item in valuePairs) { ViewData[item.Key] = item.Value; } return(View(valuePairs)); }
public PlainModel Create(PlainModel model) { _context.PlainModels.Add(model); _context.SaveChanges(); return(model); }
public PlainModel Update(PlainModel model) { _context.PlainModels.Update(model); _context.SaveChanges(); return(model); }