public async Task MultipleRulesWithFallback() { contexts = ContextCreator.Create("device", "1", Tuple.Create("SomeDeviceProp", JsonValue.NewNumber(5))); paths = new[] { "abc/somepath" }; rules = new Dictionary <string, RuleDefinition> { ["abc/somepath"] = JPadGenerator.New().AddSingleVariantRule(matcher: JsonConvert.SerializeObject(new MatcherData() { { "device.SomeDeviceProp", 10 } }), value: "BadValue") .AddSingleVariantRule(matcher: JsonConvert.SerializeObject(new Dictionary <string, object>() { { "device.SomeDeviceProp", 5 } }), value: "SomeValue").Generate(), }; await Run(async (tweek, context) => { var val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1") }, context); Assert.Equal("SomeValue", val["abc/somepath"].Value.AsString()); }); }
public async Task CalculateFilterByMatcherWithMultiIdentities() { contexts = ContextCreator.Merge( ContextCreator.Create("user", "1", Tuple.Create("SomeUserProp", JsonValue.NewNumber(10))), ContextCreator.Create("device", "1", Tuple.Create("SomeDeviceProp", JsonValue.NewNumber(5)))); paths = new[] { "abc/somepath" }; rules = new Dictionary <string, RuleDefinition> { ["abc/somepath"] = JPadGenerator.New().AddSingleVariantRule(matcher: JsonConvert.SerializeObject(new MatcherData { ["device.SomeDeviceProp"] = 5, ["user.SomeUserProp"] = 10 }), value: "SomeValue").Generate() }; await Run(async (tweek, context) => { var val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1") }, context); Assert.Equal(0, val.Count); val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("user", "1") }, context); Assert.Equal(0, val.Count); val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1"), new Identity("user", "1") }, context); Assert.Equal("SomeValue", val["abc/somepath"].Value.AsString()); }); }
public static void PlayIfPresent(this Effect effect, ContextCreator contextCreator) { if (effect != null) { effect.Play(contextCreator()); } }
public async Task CalculateWithMultiVariant() { contexts = ContextCreator.Create("device", "1", Tuple.Create("SomeDeviceProp", JsonValue.NewNumber(5))); paths = new[] { "abc/somepath" }; rules = new Dictionary <string, RuleDefinition>() { ["abc/somepath"] = JPadGenerator.New() .AddMultiVariantRule(matcher: JsonConvert.SerializeObject(new Dictionary <string, object>() { { "device.SomeDeviceProp", 5 } }), valueDistrubtions: JsonConvert.SerializeObject(new { type = "bernoulliTrial", args = 0.5 }), ownerType: "device").Generate() }; await Run(async (tweek, context) => { var val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { }, context); Assert.Equal(0, val.Count); val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1") }, context); Assert.True(val["abc/somepath"].Value.AsString() == "true" || val["abc/somepath"].Value.AsString() == "false"); await Task.WhenAll(Enumerable.Range(0, 10).Select(async x => { Assert.Equal((await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1") }, context))["abc/somepath"].Value, val["abc/somepath"].Value); })); }); }
public ActionResult ManagePassword(string s) { string oldPass = Request.Form["oldPass"]; string newPass = Request.Form["newPass"]; string confirmPass = Request.Form["confirmPass"]; if (!System.Text.RegularExpressions.Regex.IsMatch(newPass, "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{8,}$")) { Session["Error"] = "رمز عبور میبایست به طول ۸ و شامل حروف کوچک، بزرگ و اعداد باشد."; return(RedirectToAction("ManagePassword", "Account")); } if (!newPass.Equals(confirmPass)) { Session["Error"] = "رمزعبور جدید با تکرار آن مطابقت ندارد"; return(RedirectToAction("ManagePassword", "Account")); } User user = Utilities.CommonUtilities.GetUser(); if (!user.Password.Equals(oldPass)) { Session["Error"] = "رمز عبور فعلی اشتباه است."; return(RedirectToAction("ManagePassword", "Account")); } PoliceContext ctn = ContextCreator.GetInstance().GetContext(); User userUpdate = ctn.Users.FirstOrDefault(u => u.Username.Equals(user.Username)); if (userUpdate != null) { userUpdate.Password = newPass; } ctn.SaveChanges(); Session["Information"] = "رمز با موفقیت تغییر کرد."; return(RedirectToAction("MessagePage", "Default")); }
public bool GetListOfAvailableGFunc(out List <int> availableGfuncList, out string errMsg) { errMsg = ""; availableGfuncList = new List <int>(); using (var dc = ContextCreator.GetEntityContext()) { var q = dc.E_MILLPLUS_AVAILABLE_G_FUNCTIONS .Select(s => s.G_FUNC); try { availableGfuncList = q.ToList(); } catch (EntityException) { errMsg = Resources.DBConnectionProblem; return(false); } catch (InvalidOperationException exp) { errMsg = exp.Message; return(false); } if (availableGfuncList.Count == 0) { errMsg = "Не найден список поддерживаемых функций"; return(false); } return(true); } }
public async Task RuleUsingTimeBasedOperators() { contexts = ContextCreator.Merge( ContextCreator.Create("device", "1", Tuple.Create("birthday", JsonValue.NewString(DateTime.UtcNow.AddDays(-2).ToString("u")))), ContextCreator.Create("device", "2", Tuple.Create("birthday", JsonValue.NewString(DateTime.UtcNow.AddDays(-5).ToString("u"))))); paths = new[] { "abc/somepath" }; rules = new Dictionary <string, RuleDefinition>() { ["abc/somepath"] = JPadGenerator.New() .AddSingleVariantRule(JsonConvert.SerializeObject(new Dictionary <string, object>() { { "Device.birthday", new Dictionary <string, object>() { { "$withinTime", "3d" } } } }), value: "true") .AddSingleVariantRule(JsonConvert.SerializeObject(new {}), value: "false") .Generate() }; await Run(async (tweek, context) => { var val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1") }, context); Assert.Equal("true", val["abc/somepath"].Value.AsString()); val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "2") }, context); Assert.Equal("false", val["abc/somepath"].Value.AsString()); }); }
public async Task CalculateWithFixedValue() { contexts = ContextCreator.Merge(ContextCreator.Create("device", "1", Tuple.Create("@fixed:abc/somepath", JsonValue.NewString("FixedValue"))), ContextCreator.Create("device", "2", Tuple.Create("SomeDeviceProp", JsonValue.NewNumber(5))), ContextCreator.Create("device", "3", Tuple.Create("SomeDeviceProp", JsonValue.NewNumber(5)), Tuple.Create("@fixed:abc/somepath", JsonValue.NewString("FixedValue")))); paths = new[] { "abc/somepath" }; rules = new Dictionary <string, RuleDefinition>() { ["abc/somepath"] = JPadGenerator.New().AddSingleVariantRule(matcher: JsonConvert.SerializeObject(new Dictionary <string, object>() { { "device.SomeDeviceProp", 5 } }), value: "RuleBasedValue").Generate() }; await Run(async (tweek, context) => { var val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1") }, context); Assert.Equal("FixedValue", val["abc/somepath"].Value.AsString()); val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "2") }, context); Assert.Equal("RuleBasedValue", val["abc/somepath"].Value.AsString()); val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "3") }, context); Assert.Equal("FixedValue", val["abc/somepath"].Value.AsString()); }); }
public void Report_ShouldRenderDefaultView_WhenCalled() { // Arrange var mockedDbContext = ContextCreator.CreateMockedApllicationDbContext(); var mockedLiteDbContext = new Mock <IClubContext>(); var controller = new TournamentController(mockedDbContext.Object, mockedLiteDbContext.Object); // Act & Assert Assert.IsInstanceOf <ViewAsPdf>(controller.ReportTournament(3)); }
public void Constructor_ShouldCreateController_WhenValuesArePassed() { var mockedDbContext = ContextCreator.CreateMockedApllicationDbContext(); var mockedLiteDbContext = new Mock <IClubContext>(); var controller = new HomeController(mockedDbContext.Object, mockedLiteDbContext.Object); // Act & Assert Assert.IsInstanceOf <HomeController>(controller); Assert.AreSame(controller.Db, mockedDbContext.Object); Assert.AreSame(controller.LiteDb, mockedLiteDbContext.Object); }
public void Delete_ShouldRedirectToTurnament_WhenNullProvided() { // Arrange var mockedDbContext = ContextCreator.CreateMockedApllicationDbContext(); var mockedLiteDbContext = new Mock <IClubContext>(); var controller = new TournamentController(mockedDbContext.Object, mockedLiteDbContext.Object); // Act & Assert controller.WithCallTo(x => x.DeleteTournament(33)) .ShouldRedirectTo(x => x.Tournaments); }
public void Delete_ShouldRenderDefaultView_WhenCalled() { // Arrange var mockedDbContext = ContextCreator.CreateMockedApllicationDbContext(); var mockedLiteDbContext = new Mock <IClubContext>(); var controller = new TournamentController(mockedDbContext.Object, mockedLiteDbContext.Object); // Act & Assert controller.WithCallTo(x => x.DeleteTournament(3)) .ShouldRenderDefaultView(); }
public void AddTournament_ShouldReturn_WhenNullIsPassed() { // Arrange var mockedDbContext = ContextCreator.CreateMockedApllicationDbContext(); var mockedLiteDbContext = new Mock <IClubContext>(); var controller = new TournamentController(mockedDbContext.Object, mockedLiteDbContext.Object); // Act & Assert controller.WithCallTo(x => x.AddTournament(null)) .ShouldRenderDefaultView(); }
public void Players_ShouldReturnViewResult_WhenCalled() { // Arrange var mockedDbContext = ContextCreator.CreateMockedApllicationDbContext(); var mockedLiteDbContext = new Mock <IClubContext>(); var controller = new PlayerController(mockedDbContext.Object, mockedLiteDbContext.Object); // Act & Assert controller.WithCallTo(x => x.Players()) .ShouldRenderDefaultView() .WithModel <PlayersViewModel>(); }
public void Tournament_ShouldReturnUpcomingPassedTournamentsViewModel_WhenCalled() { // Arrange var mockedDbContext = ContextCreator.CreateMockedApllicationDbContext(); var mockedLiteDbContext = new Mock <IClubContext>(); var controller = new TournamentController(mockedDbContext.Object, mockedLiteDbContext.Object); // Act & Assert controller.WithCallTo(x => x.Tournaments()) .ShouldRenderDefaultView() .WithModel <UpcomingPassedTournamentsViewModel>(); }
public void testInit() { //SqlConnection connection = new SqlConnection(connectionString); //var context = new ConnectionContext(connection, true ContextCreator.Intialize(); var context = ContextCreator.GetContext(); myUow = new UnitOfWorkDapper <ConnectionContext>(context); Dictionary <string, Type> fieldIdName = new Dictionary <string, Type>(); fieldIdName.Add("id", typeof(int)); this.MyCarsRepository = new InternalRepository <Car, ConnectionContext>(myUow, tablename, fieldIdName); }
public void DeleteTournamentConfirmed_ShouldRedirectWithCallingSaveChanges_WhenCalled() { // Arrange var mockedDbContext = ContextCreator.CreateMockedApllicationDbContext(); var mockedLiteDbContext = new Mock <IClubContext>(); var controller = new TournamentController(mockedDbContext.Object, mockedLiteDbContext.Object); // Act & Assert controller.WithCallTo(x => x.DeleteTournamentConfirmed(3)) .ShouldRedirectTo(x => x.Tournaments); mockedDbContext.Verify(x => x.SaveChanges(), Times.Exactly(1)); }
void clearLuaRef() { foreach (var kv in detachs) { kv.Value(); } detachs.Clear(); detachs = null; options = null; attach = null; reload = null; creator = null; commandSetter = null; exportSetter = null; }
public object Clone() { PoliceContext contex = ContextCreator.GetInstance().GetContext(); DbSet set = contex.Set(this.GetType()); AbstractEntity clonedEntity = set.Find(this.Id) as AbstractEntity; contex.Entry(clonedEntity).State = EntityState.Detached; if (clonedEntity == null) { //TODO //throw new UserInterfaceException(27701, String.Format("امکان کپی کردن {0} با شناسه ی {1} وجود ندارد، لطفا با بخش پشتیبانی تماس بگیرید.", this.GetType(), this.ID)); throw new Exception("----abstract entity failed! ----"); } clonedEntity.Id = System.Guid.NewGuid().GetHashCode(); return(clonedEntity); }
public async Task EmptyFixedKeyIsIgnoredInScan() { contexts = ContextCreator.Merge(ContextCreator.Create("device", "1", Tuple.Create("@fixed:", JsonValue.NewString("FixedValue")))); paths = new[] { "abc/somepath" }; rules = rules = new Dictionary <string, RuleDefinition> { ["abc/somepath"] = JPadGenerator.New().AddSingleVariantRule(matcher: "{}", value: "SomeValue").Generate() }; await Run(async (tweek, context) => { var val = await tweek.GetContextAndCalculate("_", new HashSet <Identity> { new Identity("device", "1") }, context); Assert.Equal("SomeValue", val["abc/somepath"].Value.AsString()); }); }
public async Task MultipleRules() { contexts = ContextCreator.Create("device", "1"); paths = new[] { "abc/somepath" }; rules = new Dictionary <string, RuleDefinition> { ["abc/otherpath"] = JPadGenerator.New().AddSingleVariantRule(matcher: "{}", value: "BadValue").Generate(), ["abc/somepath"] = JPadGenerator.New().AddSingleVariantRule(matcher: "{}", value: "SomeValue") .AddSingleVariantRule(matcher: "{}", value: "BadValue").Generate(), }; await Run(async (tweek, context) => { var val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1") }, context); Assert.Equal("SomeValue", val["abc/somepath"].Value.AsString()); }); }
public void AddTournament_ShouldRedirect_WhenTournamentIsPassed() { // Arrange var mockedDbContext = ContextCreator.CreateMockedApllicationDbContext(); var mockedLiteDbContext = new Mock <IClubContext>(); var controller = new TournamentController(mockedDbContext.Object, mockedLiteDbContext.Object); var model = new TournamentInputModel() { Name = "testTest", StartDate = new DateTime(2015, 1, 18), EndDate = new DateTime(2020, 1, 18), Rounds = 3, Country = "Bulgariikata2", Description = "TestTestTest" }; // Act & Assert controller.WithCallTo(x => x.AddTournament(model)) .ShouldRedirectTo(x => x.Tournaments); }
public async Task CalculateWithRecursiveMatcher() { contexts = ContextCreator.Merge( ContextCreator.Create("device", "1", Tuple.Create("SomeDeviceProp", JsonValue.NewNumber(5))), ContextCreator.Create("device", "2", Tuple.Create("@fixed:abc/dep_path2", JsonValue.NewBoolean(true)), Tuple.Create("SomeDeviceProp", JsonValue.NewNumber(5))) ); paths = new[] { "abc/somepath", "abc/dep_path1", "abc/dep_path2" }; rules = new Dictionary <string, RuleDefinition>() { ["abc/dep_path1"] = JPadGenerator.New().AddSingleVariantRule(matcher: JsonConvert.SerializeObject(new Dictionary <string, object>() { { "device.SomeDeviceProp", 5 } }), value: true).Generate(), ["abc/somepath"] = JPadGenerator.New().AddSingleVariantRule(matcher: JsonConvert.SerializeObject(new Dictionary <string, object>() { { "@@key:abc/dep_path1", true }, { "keys.abc/dep_path2", true } }), value: true).Generate() }; await Run(async (tweek, context) => { var val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1") }, context); Assert.Equal(1, val.Count); Assert.Equal("true", val["abc/dep_path1"].Value.AsString()); val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "2") }, context); Assert.Equal(3, val.Count); Assert.Equal("true", val["abc/dep_path1"].Value.AsString()); Assert.Equal("true", val["abc/dep_path2"].Value.AsString()); Assert.Equal("true", val["abc/somepath"].Value.AsString()); }); }
public async Task ContextKeysShouldBeCaseInsensitive() { contexts = ContextCreator.Create("device", "1", Tuple.Create("someDeviceProp", JsonValue.NewNumber(5))); paths = new[] { "abc/somepath" }; rules = new Dictionary <string, RuleDefinition>() { ["abc/somepath"] = JPadGenerator.New() .AddSingleVariantRule(matcher: JsonConvert.SerializeObject(new Dictionary <string, object>() { { "Device.sOmeDeviceProp", 5 } }), value: "true").Generate() }; await Run(async (tweek, context) => { var val = await tweek.GetContextAndCalculate("abc/_", new HashSet <Identity> { new Identity("device", "1") }, context); Assert.Equal("true", val["abc/somepath"].Value.AsString()); }); }
/// <summary> /// Возвращает ключевые характеристики первого найденного станка. /// </summary> /// <param name="machineId"></param> /// <param name="bMin">минимальный угол по оси В</param> /// <param name="bMax">максимальный угол по оси В</param> /// <param name="spinSpeedMax">ьфксимальная скорость вращения шпинделя</param> /// <param name="errMsg"></param> /// <returns>Еси ничего не найдено, возвращает углы -360+360 и скорость 1234567890 </returns> public bool GetMachineParams(int machineId, out decimal bMin, out decimal bMax, out int spinSpeedMax, out string errMsg) { using (var dc = ContextCreator.GetEntityContext()) { bMin = -360; bMax = 360; spinSpeedMax = 1234567890; errMsg = ""; try { var query = dc.E_MACHINE_SPISOK .Where(w => w.Id_marka_machine == machineId) .Select(s => s).First(); if (query.Fourth_axis_min != null) { bMin = (decimal)query.Fourth_axis_min; } if (query.Fourth_axis_max != null) { bMax = (decimal)query.Fourth_axis_max; } if (query.SpinMaxSpeed != null) { spinSpeedMax = (int)query.SpinMaxSpeed; } } catch (EntityException) { errMsg = Resources.DBConnectionProblem; return(false); } catch (InvalidOperationException exp) { errMsg = exp.Message; return(false); } } return(true); }
void initLua(LuaEnv env) { if (env == null) { luaEnv = new LuaEnv(); disposeLuaEnv = true; } else { luaEnv = env; } creator = luaEnv.LoadString <Func <ContextCreator> >(@" return (require 'xuui').new ", "@xuui_init.lua")(); commandSetter = luaEnv.LoadString <Func <Action <LuaTable, string, string, object> > >(@" return function(options, module_name, method_name, obj) options.data[module_name] = options.data[module_name] or {} options.commands = options.commands or {} local func = obj[method_name] options.commands[string.format('%s.%s', module_name, method_name)] = function(...) func(obj, ...) end end ", "@eventSetter.lua")(); exportSetter = luaEnv.LoadString <Func <Action <LuaTable, string, string, object> > >(@" return function(options, module_name, method_name, obj) options.data[module_name] = options.data[module_name] or {} options.exports[module_name] = options.exports[module_name] or {} local func = obj[method_name] options.exports[module_name][method_name] = function(...) func(obj, ...) end end ", "@exportSetter.lua")(); }
public async Task BadKeyShouldReturnError() { contexts = ContextCreator.Create("device", "1", Tuple.Create("SomeDeviceProp", JsonValue.NewNumber(3))); paths = new[] { "abc/bad_path", "abc/good_path" }; rules = new Dictionary <string, RuleDefinition> { ["abc/bad_path"] = JPadGenerator.New() .AddSingleVariantRule(JsonConvert.SerializeObject(new MatcherData { ["device.SomeDeviceProp"] = new string[] {} }), "BadValue") .Generate(), ["abc/good_path"] = JPadGenerator.New().AddSingleVariantRule("{}", "SomeValue").Generate() }; await Run(async (tweek, context) => { var identities = new HashSet <Identity> { new Identity("device", "1") }; var val = await tweek.GetContextAndCalculate("_", identities, context); Assert.NotNull(val["abc/bad_path"].Exception); Assert.Equal(JsonValue.Null, val["abc/bad_path"].Value); Assert.Equal("SomeValue", val["abc/good_path"].Value.AsString()); val = await tweek.GetContextAndCalculate("abc/_", identities, context); Assert.NotNull(val["abc/bad_path"].Exception); Assert.Equal(JsonValue.Null, val["abc/bad_path"].Value); Assert.Equal("SomeValue", val["abc/good_path"].Value.AsString()); val = await tweek.GetContextAndCalculate("abc/bad_path", identities, context); Assert.NotNull(val["abc/bad_path"].Exception); Assert.Equal(JsonValue.Null, val["abc/bad_path"].Value); }); }
public static void ClassCleanup() { ContextCreator.Dispose(); }
protected BaseRepositoryFixture() { Context = ContextCreator.CreateContext(); InitDatabase(); }
public UserActivityReadOnlyRepository(DbSet <UserActivity> repository, ContextCreator creator) : base(repository, creator) { }