public void OnUpdate(SomeObject someobj) { _so = someobj; OnMyTestCallBackEvent(new MyTestCallBackEventArgs { SomeObject = _so }); }
public SomeTimedModule( SomeInnerModule innerModule, SomeObject someObject) { InnerModule = innerModule; SomeObject = someObject; }
public void TestObjectExpirationAfterUpdate([ValueSource(nameof(ExpirationSettingNames))] string expirationSetting) { if (!SupportsDefaultExpiration) { Assert.Ignore("Provider does not support default expiration settings"); } const int expirySeconds = 3; const string key = "keyTestObjectExpirationAfterUpdate"; var obj = new SomeObject { Id = 2 }; var cache = GetCacheForExpiration("TestObjectExpirationAfterUpdate", expirationSetting, expirySeconds); Assert.That(cache.Get(key), Is.Null, "Unexpected entry for key"); cache.Put(key, obj); Assert.That(cache.Get(key), Is.Not.Null, "Missing entry for key"); // This forces an object update cache.Put(key, obj); Assert.That(cache.Get(key), Is.Not.Null, "Missing entry for key after update"); // Wait Thread.Sleep(TimeSpan.FromSeconds(expirySeconds + 2)); // Check it expired Assert.That(cache.Get(key), Is.Null, "Unexpected entry for key after expiration"); }
public void TestSlidingExpiration() { if (!SupportsSlidingExpiration) { Assert.Ignore("Provider does not support sliding expiration settings"); } const int expirySeconds = 3; const string key = "keyTestSlidingExpiration"; var obj = new SomeObject { Id = 2 }; var props = GetPropertiesForExpiration(Cfg.Environment.CacheDefaultExpiration, expirySeconds.ToString()); props["cache.use_sliding_expiration"] = "true"; var cache = DefaultProvider.BuildCache("TestObjectExpiration", props); cache.Put(key, obj); // Wait up to 1 sec before expiration Thread.Sleep(TimeSpan.FromSeconds(expirySeconds - 1)); Assert.That(cache.Get(key), Is.Not.Null, "Missing entry for key"); // Wait up to 1 sec before expiration again Thread.Sleep(TimeSpan.FromSeconds(expirySeconds - 1)); Assert.That(cache.Get(key), Is.Not.Null, "Missing entry for key after get and wait less than expiration"); // Wait expiration Thread.Sleep(TimeSpan.FromSeconds(expirySeconds + 1)); // Check it expired Assert.That(cache.Get(key), Is.Null, "Unexpected entry for key after expiration"); }
public SomeObject Get() { try { using (IDbConnection db = new NpgsqlConnection(settings.ConnectionString)) { var someObject = new SomeObject(); var id = db.GetList <ResultModel>().OrderBy(t => t.Id).Last().Id; someObject.Result = new Result(db.Get <ResultModel>(id)); var traks = db.GetList <TraksModel>().Where(t => t.ResultId == id).ToArray(); someObject.Result.SetTraks(traks); for (var i = 0; i < someObject.Result.Traks.Length; i++) { var sets = db.GetList <SetsModel>().Where(s => s.TraksId == traks[i].Id).ToArray(); someObject.Result.Traks[i].SetSets(sets); for (var j = 0; j < someObject.Result.Traks[i].Sets.Length; j++) { var items = db.GetList <ItemsModel>().Where(itm => itm.SetsId == sets[j].Id).ToArray(); someObject.Result.Traks[i].Sets[j].SetItems(items); } } return(someObject); } } catch (Exception ex) { return(new SomeObject() { ErrorMessage = ex.Message }); } }
public void Create(SomeObject someObject) { try { var randValue = new Random(); using (var db = new NpgsqlConnection(settings.ConnectionString)) { var res = new ResultModel(someObject.Result); var id = db.Insert(res); foreach (var trak in res.TraksModel) { trak.ResultId = id; var tId = db.Insert(trak); foreach (var sets in trak.SetsModel) { sets.TraksId = tId; var sId = db.Insert(sets); foreach (var item in sets.ItemsModel) { item.SetsId = sId; item.RandValue = randValue.Next(10, 100); db.Insert(item); } } } } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public void When_returning_more_than_max_pool_size() { Func <SomeObject> factory = () => new SomeObject(); const int MaxCount = 1; using (IEasyPool <SomeObject> pool = new EasyPool <SomeObject>(factory, null, MaxCount)) { pool.Count.ShouldBe((uint)0); var obj1 = new SomeObject(); pool.Return(obj1).ShouldBeTrue(); pool.Count.ShouldBe((uint)1); var obj2 = new SomeObject(); pool.Return(obj2).ShouldBeFalse(); pool.Count.ShouldBe((uint)1); var pooledObj = pool.Rent(); pooledObj.ShouldBe(obj1); pool.Count.ShouldBe((uint)0); } }
public void TestObjectExpirationAfterUpdate() { var obj = new SomeObject { Id = 2 }; var localProps = new Dictionary <string, string> { { "expiration", ExpirySeconds.ToString(CultureInfo.InvariantCulture) } }; var cache = provider.BuildCache(RegionName, localProps); Assert.IsNull(cache.Get(obj)); cache.Put(Key, obj); // This forces an object update cache.Put(Key, obj); // Wait Thread.Sleep(TimeSpan.FromSeconds(ExpirySeconds + 2)); // Check it expired Assert.IsNull(cache.Get(Key)); }
public void Setup() { _filter = new PassParametersDuringRedirectAttribute(); _someObject = new SomeObject { One = 1, Two = "two" }; }
public static void Test() { var someObject = new SomeObject(); Setter <string> setter = (v) => { t.SomeProperty = v; }; setter.DynamicInvoke(new object[] { propValue }); }
public async Task TestObjectExpirationAfterUpdateAsync([ValueSource(nameof(ExpirationSettingNames))] string expirationSetting) { if (!SupportsDefaultExpiration) { Assert.Ignore("Provider does not support default expiration settings"); } const int expirySeconds = 3; const string key = "keyTestObjectExpirationAfterUpdate"; var obj = new SomeObject { Id = 2 }; var cache = GetCacheForExpiration("TestObjectExpirationAfterUpdate", expirationSetting, expirySeconds); Assert.That(await(cache.GetAsync(key, CancellationToken.None)), Is.Null, "Unexpected entry for key"); await(cache.PutAsync(key, obj, CancellationToken.None)); Assert.That(await(cache.GetAsync(key, CancellationToken.None)), Is.Not.Null, "Missing entry for key"); // This forces an object update await(cache.PutAsync(key, obj, CancellationToken.None)); Assert.That(await(cache.GetAsync(key, CancellationToken.None)), Is.Not.Null, "Missing entry for key after update"); // Wait await(Task.Delay(TimeSpan.FromSeconds(expirySeconds + 2))); // Check it expired Assert.That(await(cache.GetAsync(key, CancellationToken.None)), Is.Null, "Unexpected entry for key after expiration"); }
public static void ToObject_Returns_Expected(SomeObject expected, Vertex sut) { sut.Properties[nameof(SomeObject.BooleanProperty)] = new[] { new VertexPropertyValue { Value = expected.BooleanProperty } }; sut.Properties[nameof(SomeObject.BooleanEnumerableProperty)] = expected.BooleanEnumerableProperty.Select(v => new VertexPropertyValue { Value = v }).ToList(); sut.Properties[nameof(SomeObject.DecimalProperty)] = new[] { new VertexPropertyValue { Value = expected.DecimalProperty } }; sut.Properties[nameof(SomeObject.DecimalEnumerableProperty)] = expected.DecimalEnumerableProperty.Select(v => new VertexPropertyValue { Value = v }).ToList(); sut.Properties[nameof(SomeObject.IntegerProperty)] = new[] { new VertexPropertyValue { Value = expected.IntegerProperty } }; sut.Properties[nameof(SomeObject.IntegerEnumerableProperty)] = expected.IntegerEnumerableProperty.Select(v => new VertexPropertyValue { Value = v }).ToList(); sut.Properties[nameof(SomeObject.StringProperty)] = new[] { new VertexPropertyValue { Value = expected.StringProperty } }; sut.Properties[nameof(SomeObject.StringEnumerableProperty)] = expected.StringEnumerableProperty.Select(v => new VertexPropertyValue { Value = v }).ToList(); var result = sut.ToObject <SomeObject>(); expected.Should().BeEquivalentTo(result); }
public void TestObjectExpirationAfterUpdate() { const int expirySeconds = 3; const string key = "key"; var obj = new SomeObject(); obj.Id = 2; var localProps = new Dictionary <string, string>(); localProps.Add("expiration", expirySeconds.ToString()); ICache cache = provider.BuildCache("nunit", localProps); Assert.IsNull(cache.Get(obj)); cache.Put(key, obj); // This forces an object update cache.Put(key, obj); // Wait Thread.Sleep(TimeSpan.FromSeconds(expirySeconds + 2)); // Check it expired Assert.IsNull(cache.Get(key)); }
public void AddItem(SomeObject item) { lock (_processingQueue) { _processingQueue.Enqueue(item); } _waitHandle.Set(); }
public void Same_instance_may_be_registared_twice() { var ioc = IoC.New(); var obj = new SomeObject(); ioc.RegisterInstance<ISomeInterface>(obj); AssertIt.Succeeds(() => ioc.RegisterInstance<ISomeInterface>(obj)); }
public MyClass() { object1 = new SomeObject(); object2 = new AnotherObject(); object1.AThreadedEvent += ThreadedEventHandler1; object2.AnotherThreadedEvent += ThreadedEventHandler2; }
void ReturnSomeObject(SomeObject item) { if (SomeObjectsPulledFromPool.Contains(item)) { _someObjectPool.ReturnItem(item); SomeObjectsPulledFromPool.Remove(item); } }
public void M() { Mapper.CreateMap<SomeObject, SomeOtherObject>(); SomeObject source = new SomeObject {Name = "An Object"}; SomeOtherObject target = new SomeOtherObject {Id = 123}; Mapper.Map(source, target); Assert.AreEqual(123, target.Id); Assert.AreEqual("An Object", target.Name); }
static void Main(string[] args) { dynamic obj = new SomeObject(); var meth = obj.GetType().GetMethod("someMethodName"); meth.Invoke(obj, new object[1] { "hello" }); }
public void And_instance_is_previously_registered_It_is_resolved_like_this() { var ioc = IoC.New(); var obj = new SomeObject(); ioc.RegisterInstance<ISomeInterface>(obj); var obj2 = ioc.Resolve<ISomeInterface>(); Assert.That(obj, Is.SameAs(obj)); }
public void It_should_be_used_regardless_local_parameters() { var ioc = IoC.New(); var obj = new SomeObject(); ioc.RegisterInstance<ISomeInterface>(obj); Assert.That(ioc.Resolve<ISomeInterface>(), Is.SameAs(obj)); Assert.That(ioc.Resolve<ISomeInterface>(() => null), Is.SameAs(obj)); }
protected void Page_Load(object sender, EventArgs e) { Response.Clear(); Response.ContentType = "application/json"; SomeObject result = ...fetch from db or something var serializer = new JavaScriptSerializer(); string json = serializer.Serialize(result); Response.Write(json); }
public ProtobufGrpcClientCallTest(SomeObject payload) { _payload = payload; _httpHandler = new StubHttpMessageHandler(ProtobufMarshallerFactory.Default, _payload); _channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions { HttpHandler = _httpHandler }); _proxy = _channel.CreateGrpcService <ITestService>(); }
public SomeTypeBindingList(SomeObject someObject) { _someObject = someObject; var observableCollection = _someObject.Items as ObservableCollection <SomeType>; if (observableCollection != null) { observableCollection.CollectionChanged += ObservableCollectionOnCollectionChanged; } }
public MagicOnionServerCallTest(SomeObject payload) { _server = new TestServer(new WebHostBuilder().UseStartup <Startup>()); _client = _server.CreateClient(); _request = new StubHttpRequest( _client, "/ITestServiceMagicOnion/PingPong", MessageSerializer.Create(MessagePackMarshallerFactory.Default, payload)); }
public void M() { Mapper.CreateMap <SomeObject, SomeOtherObject>(); SomeObject source = GetSource(); SomeOtherObject target = GetTarget(); Mapper.Map(source, target); Assert.AreEqual(123, target.Id); Assert.AreEqual("An Object", target.Name); }
public NativeGrpcServerCallTest(SomeObject payload) { _server = new TestServer(new WebHostBuilder().UseStartup <Startup>()); _client = _server.CreateClient(); _request = new StubHttpRequest( _client, "/TestServiceNative/PingPong", MessageSerializer.Create(DomainExtensions.CopyToProto(payload))); }
public static vwContact Contacts(this SomeObject someObject) { var dbContext = new LegacyDbContext(); var contacts = from o in someObject join c in dbContext.vwContact on o.ContactId == c.KeyField select c; return(contacts); }
static void Main() { SomeObject obj = new SomeObject(); obj.X = 1; // could be a public field or a property obj.Y = 2; // could be a public field or a property // This is an error if X is a property // SomeFunction( ref obj.X ); }
public void AddExtraObject_CanBeFound() { var objectToAdd = new SomeObject(); AddExtraObjects(objectToAdd); _baseObject.Initialize(); Assert.That(_baseObject.TryFind(out SomeObject foundObject), Is.True); Assert.AreSame(objectToAdd, foundObject); }
public MagicOnionClientCallTest(SomeObject payload) { _payload = payload; _httpHandler = new StubHttpMessageHandler(MessagePackMarshallerFactory.Default, payload); _channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions { HttpHandler = _httpHandler }); _proxy = MagicOnion.Client.MagicOnionClient.Create <ITestServiceMagicOnion>(_channel); }
public ProtobufGrpcServerCallTest(SomeObject payload) { _server = new TestServer(new WebHostBuilder().UseStartup <Startup>()); _client = _server.CreateClient(); _request = new StubHttpRequest( _client, "/ServiceModel.Grpc.Benchmarks.Domain.TestService/PingPong", MessageSerializer.Create(ProtobufMarshallerFactory.Default, payload)); }
public void CanRetriveValiationResults() { Validator validator = new Validator(); SomeObject invalidObject = new SomeObject(); ICollection<IValidationResult> results = validator.ValidationResultsFor(invalidObject); Assert.That(results.Count, Is.EqualTo(1)); Assert.That(results.First().PropertyName, Is.EqualTo("Name")); Assert.That(results.First().ClassContext, Is.EqualTo(typeof(SomeObject))); Assert.That(results.First().Message, Is.EqualTo("Dude...the name please!!")); }
public NativeGrpcClientCallTest(SomeObject payload) { _payload = DomainExtensions.CopyToProto(payload); _httpHandler = new StubHttpMessageHandler(_payload); _channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions { HttpHandler = _httpHandler }); _proxy = new TestServiceNative.TestServiceNativeClient(_channel); }
public void CanValidateObject() { Validator validator = new Validator(); SomeObject invalidObject = new SomeObject(); Assert.That(validator.IsValid(invalidObject), Is.False); SomeObject validObject = new SomeObject() { Name = "" }; Assert.That(validator.IsValid(validObject), Is.True); }
public void CanRetriveValiationResults() { var validator = new Validator(); var invalidObject = new SomeObject(); ICollection<IValidationResult> results = validator.ValidationResultsFor(invalidObject); Assert.AreEqual(1, results.Count); Assert.AreEqual("Name", results.First().PropertyName); Assert.AreEqual(typeof (SomeObject), results.First().ClassContext); Assert.AreEqual("Dude...the name please!!", results.First().Message); }
public void They_should_not_be_mixed_with_not_mocks() { ISomeInterface obj = new SomeObject(); ISomeInterface2 obj2 = new SomeObject2(); var mock = new Mock<ISomeInterface>(); var mock2 = new Mock<ISomeInterface2>(); AssertIt.Succeeds(() => IoC.New(obj, obj2)); AssertIt.Succeeds(() => IoC.New(mock, mock2)); AssertIt.Fails(() => IoC.New(obj, mock)); }
public void CanValidateObject() { var validator = new Validator(); var invalidObject = new SomeObject(); Assert.IsFalse(validator.IsValid(invalidObject)); var validObject = new SomeObject { Name = "" }; Assert.IsTrue(validator.IsValid(validObject)); }
public void HandlesBase64EncodedStrings() { var item = new SomeObject { Name = "Ferris Bueller", Content = "Day off", Description = "stuff" }; var json = new SimpleJsonSerializer().Serialize(item); Assert.Equal("{\"name\":\"RmVycmlzIEJ1ZWxsZXI=\",\"description\":\"stuff\",\"content\":\"RGF5IG9mZg==\"}", json); }
public void CanTransferValidationResultsToModelState() { //RegisterAdditionalServices(container); var validator = new Validator(); var invalidObject = new SomeObject { LastName = null, FirstName = "ThisFirstNameIsTooLong", Street = " ", MiddleName = "valid" }; Assert.IsFalse(validator.IsValid(invalidObject)); var results = validator.ValidationResultsFor(invalidObject); Assert.IsNotNull(results); Assert.AreEqual(3, results.Count, "Wrong number of validation messages encountered."); ModelStateDictionary modelState = new ModelStateDictionary(); Assert.IsNotNull(modelState); Assert.AreEqual(0, modelState.Values.Count); invalidObject.TransferValidationMessagesTo(modelState); Assert.AreEqual(3, modelState.Values.Count); var resultsList = new List<string>(); foreach (var result in modelState.Values) { foreach (var errs in result.Errors) { resultsList.Add(errs.ErrorMessage); } } var errors = new[] { "LastName: Dude...the name please!!", "Street: may not be null or empty", "FirstName: length must be between 0 and 10" }; Assert.AreEqual(resultsList.Count, errors.Length, "Number of error messages do not match"); foreach (var error in errors) { Assert.IsTrue(resultsList.Contains(error), "Expected error \"" + error + "\" not found"); } }
public void It_should_be_used_like_this() { var ioc = IoC.New(); var obj = new SomeObject(); ioc.Setup() .Map<ISomeInterface>().To(obj) .Map<ISomeInterface2>().To(() => new SomeObject2()); var obj2 = ioc.Resolve<ISomeInterface>(); var obj3 = ioc.Resolve<ISomeInterface2>(); Assert.That(obj2, Is.SameAs(obj)); Assert.That(obj3, Is.TypeOf<SomeObject2>()); }
/// <summary> /// int[] read/write /// </summary> public static uint CMPObjectArray () { SomeObject [] arr = new SomeObject [3]; arr [0] = new SomeObject (7); arr [1] = new SomeObject (9); arr [2] = new SomeObject (44); if (arr [0].value != 7) return 0; if (arr [1].value != 9) return 0; if (arr [2].value != 44) return 0; return 1; }
public void CanValidateObject() { var validator = new Validator(); var invalidObject = new SomeObject { LastName = "", FirstName = "ThisFirstNameIsTooLong", Street = null }; Assert.IsFalse(validator.IsValid(invalidObject)); var validObject = new SomeObject { LastName = "Last", FirstName = "First", Street = "SomeStreet" }; Assert.IsTrue(validator.IsValid(validObject)); }
public void TestNonEqualObjectsWithEqualHashCodeAndToString() { var obj1 = new SomeObject(); var obj2 = new SomeObject(); obj1.Id = 1; obj2.Id = 2; ICache cache = provider.BuildCache("nunit", props); Assert.IsNull(cache.Get(obj2)); cache.Put(obj1, obj1); Assert.AreEqual(obj1, cache.Get(obj1)); Assert.IsNull(cache.Get(obj2)); }
public ActionResult AnotherAction(SomeObject obj) { return View(obj); }
public void TestObjectExpirationAfterUpdate() { var obj = new SomeObject { Id = 2 }; var localProps = new Dictionary<string, string> { { "expiration", ExpirySeconds.ToString(CultureInfo.InvariantCulture) } }; var cache = provider.BuildCache(RegionName, localProps); Assert.IsNull(cache.Get(obj)); cache.Put(Key, obj); // This forces an object update cache.Put(Key, obj); // Wait Thread.Sleep(TimeSpan.FromSeconds(ExpirySeconds + 2)); // Check it expired Assert.IsNull(cache.Get(Key)); }
public void WithRangeQuery() { using (var _documentStore = NewDocumentStore()) { _documentStore.DatabaseCommands.PutIndex("SomeObjects/BasicStuff" , new IndexDefinition { Map = "from doc in docs.SomeObjects\r\nselect new { IntField = (int)doc.IntField, StringField = doc.StringField }", SortOptions = new Dictionary<string, SortOptions> { { "IntField", SortOptions.Int } }, }); using (IDocumentSession session = _documentStore.OpenSession()) { DateTime startedAt = DateTime.UtcNow; for (int i = 0; i < 40; i++) { var p = new SomeObject { IntField = i, StringField = "user " + i, }; session.Store(p); } session.SaveChanges(); } WaitForIndexing(_documentStore); using (IDocumentSession session = _documentStore.OpenSession()) { RavenQueryStatistics stats; var list = session.Query<SomeObject>() .Statistics(out stats) .Where(p => p.StringField == "user 1") .ToList(); Assert.Equal("SomeObjects/BasicStuff", stats.IndexName); } using (IDocumentSession session = _documentStore.OpenSession()) { RavenQueryStatistics stats; var list = session.Query<SomeObject>() .Statistics(out stats) .Where(p => p.IntField > 150000 && p.IntField < 300000) .ToList(); Assert.Equal("SomeObjects/BasicStuff", stats.IndexName); } using (IDocumentSession session = _documentStore.OpenSession()) { RavenQueryStatistics stats; var list = session.Query<SomeObject>() .Statistics(out stats) .Where(p => p.StringField == "user 1" && p.IntField > 150000 && p.IntField < 300000) .ToList(); Assert.Equal("SomeObjects/BasicStuff", stats.IndexName); } } }
public void CreateSub() { someObject = _objectFactory.Create(); }
public SomeMainModule(IFactory<SomeObject> objectFactory) { _objectFactory = objectFactory; someObject = _objectFactory.Create(); }
public SomeInnerModule(SomeObject someObject) { SomeObject = someObject; }
public void Serializer_does_not_emit_private_state_of_Confirmation_objects() { var log = ""; using (Log.Events().Subscribe(e => log += JsonConvert.SerializeObject(e))) using (var a = Log.Enter(() => { })) { var response = new SomeObject { yes = "this should be in the log output", no = "this should not be in the log output" }; a.Confirm(() => new { response.yes }); } Console.WriteLine(log); log.Should().NotContain("this should not be in the log output"); }
public void TestObjectExpirationAfterUpdate() { const int expirySeconds = 3; const string key = "key"; var obj = new SomeObject(); obj.Id = 2; var localProps = new Dictionary<string, string>(); localProps.Add("expiration", expirySeconds.ToString()); ICache cache = provider.BuildCache("nunit", localProps); Assert.IsNull(cache.Get(obj)); cache.Put(key, obj); // This forces an object update cache.Put(key, obj); // Wait Thread.Sleep(TimeSpan.FromSeconds(expirySeconds + 2)); // Check it expired Assert.IsNull(cache.Get(key)); }