public SensorErrorTests() { registry = new SensorRegistry(); peakyService = new PeakyService( configureServices: s => s.AddSingleton(registry)); apiClient = peakyService.CreateHttpClient(); sensorName = Any.AlphanumericString(10, 20); }
public SensorRoutingTests() { registry = new SensorRegistry(DiagnosticSensor.DiscoverSensors()); var peaky = new PeakyService(configureServices: s => s.AddSingleton(registry)); apiClient = peaky.CreateHttpClient(); sensorName = Any.AlphanumericString(10, 20); }
public void All_sensors_can_be_queried_at_once() { var value = Any.AlphanumericString(20, 100); TestSensor.GetSensorValue = () => value; var response = apiClient.GetStringAsync("http://blammo.com/sensors/").Result; Console.WriteLine(response); response.Should().Contain(value); }
public void Serializer_DeserializeEvent_finds_the_correct_event_type_when_EventNameAttribute_is_used() { var original = new EventTests.TestEventWithCustomName { AggregateId = Any.Guid(), SequenceNumber = Any.PositiveInt(), Value = Any.AlphanumericString(100) }; var deserialized = Serializer.DeserializeEvent("Order", "Bob", original.AggregateId, original.SequenceNumber, original.Timestamp, original.ToJson()); deserialized.ShouldBeEquivalentTo(original); }
public void When_given_a_GetString_class_it_gets_the_hard_coded_string() { var @namespace = "_" + Any.AlphanumericString(1, 10); var typeName = "_" + Any.AlphanumericString(1, 10); var expectedSource = "_" + Any.AlphanumericString(1, 10); var proxySource = CodeSamples.GetStringSource(@namespace, typeName, expectedSource); var asm = CompileText(null, proxySource); GetValue <string>(asm, "GetString", typeName, @namespace) .Should().Be(expectedSource); asm.GetNamespaces() .ShouldAllBeEquivalentTo(new[] { @namespace }); }
public override void A_clock_cannot_be_moved_to_a_prior_time() { // arrange var name = Any.AlphanumericString(8, 8); CreateClock(name, DateTimeOffset.UtcNow); // act Action moveBackwards = () => AdvanceClock(DateTimeOffset.UtcNow.Subtract(TimeSpan.FromSeconds(5)), name).Wait(); // assert moveBackwards.ShouldThrow <InvalidOperationException>() .And .Message .Should() .Contain("A clock cannot be moved backward"); }
public void When_Updates_To_Properties_Are_Delayed_Then_They_Must_Be_Updated_After_Calling_SaveChanges() { var prods = Any.Products().ToArray(); using (var scenario = new ODataScenario() .WithProducts(prods.AsQueryable()) .Start()) { var context = GetDataServiceContext(scenario.GetBaseAddress()); context.MergeOption = MergeOption.OverwriteChanges; var dQuery = context.CreateQuery <Product>("/" + "Products"); var products = context.ExecuteAsync <Product, IProduct>(dQuery).Result; Product prod1 = products.CurrentPage[1] as Product; string newCategory = Any.AlphanumericString(); prod1.Category = newCategory; prod1.CallOnPropertyChanged("Category"); var productFetcher = TestRestShallowObjectFetcher.CreateFetcher(context, prod1); productFetcher.UpdateAsync(prod1, true).Wait(); Product prod2 = products.CurrentPage[2] as Product; string newName = Any.CompanyName(); prod2.Name = newName; prod2.CallOnPropertyChanged("Name"); productFetcher = TestRestShallowObjectFetcher.CreateFetcher(context, prod2); productFetcher.UpdateAsync(prod2, true).Wait(); Product prod3 = products.CurrentPage[3] as Product; decimal newPrice = Any.Decimal(); prod3.Price = newPrice; prod3.CallOnPropertyChanged("Price"); productFetcher = TestRestShallowObjectFetcher.CreateFetcher(context, prod3); productFetcher.UpdateAsync(prod3, true).Wait(); var response = context.SaveChangesAsync().Result; response.Count().Should().Be(3); // Make sure everything is updated on the server var updatedProducts = context.ExecuteAsync <Product, IProduct>(dQuery).Result; updatedProducts.CurrentPage.Count.Should().Be(5); (updatedProducts.CurrentPage[1] as Product).Category.Should().Be(newCategory); (updatedProducts.CurrentPage[2] as Product).Name.Should().Be(newName); (updatedProducts.CurrentPage[3] as Product).Price.Should().Be(newPrice); } }
public void When_Updates_To_Entities_Are_Batched_Then_Entities_Must_Be_Updated_On_Server() { var prods = Any.Products().ToArray(); using (var scenario = new ODataScenario() .WithProducts(prods.AsQueryable()) .Start()) { var context = GetDataServiceContext(scenario.GetBaseAddress()); context.MergeOption = MergeOption.OverwriteChanges; var dQuery = context.CreateQuery <Product>("/" + "Products"); var products = context.ExecuteAsync <Product, IProduct>(dQuery).Result; Product prod1 = products.CurrentPage[1] as Product; string newCategory = Any.AlphanumericString(); prod1.Category = newCategory; prod1.CallOnPropertyChanged("Category"); Product prod2 = products.CurrentPage[2] as Product; string newName = Any.CompanyName(); prod2.Name = newName; prod2.CallOnPropertyChanged("Name"); Product prod3 = products.CurrentPage[3] as Product; decimal newPrice = Any.Decimal(); prod3.Price = newPrice; prod3.CallOnPropertyChanged("Price"); var response = context.SaveChangesAsync(SaveChangesOptions.BatchWithSingleChangeset).Result; response.Count().Should().Be(3); response.IsBatchResponse.Should().BeTrue(); var updatedProducts = context.ExecuteAsync <Product, IProduct>(dQuery).Result; updatedProducts.CurrentPage.Count.Should().Be(5); (updatedProducts.CurrentPage[1] as Product).Category.Should().Be(newCategory); (updatedProducts.CurrentPage[2] as Product).Name.Should().Be(newName); (updatedProducts.CurrentPage[3] as Product).Price.Should().Be(newPrice); } }
public void When_Adding_EntityType_With_Partial_Properties_Then_It_Must_Be_Added_To_Server_With_Partial_Properties() { using (var scenario = new ODataScenario() .WithProducts(Any.Products()) .Start()) { var context = GetDataServiceContext(scenario.GetBaseAddress()); var dQuery = context.CreateQuery <Product>("/" + "Products"); var products = context.ExecuteAsync <Product, IProduct>(dQuery).Result; products.CurrentPage.Count.Should().Be(5); var newProduct = new Product(); string newName = Any.CompanyName(); newProduct.Id = 6; newProduct.Name = newName; newProduct.Price = Any.Decimal(); newProduct.Category = Any.AlphanumericString(); // calling 'OnPropertyChanged' only for 'Id' and 'Name' properties newProduct.CallOnPropertyChanged("Id"); newProduct.CallOnPropertyChanged("Name"); context.AddObject("Products", newProduct); context.SaveChangesAsync().Wait(); var updatedProducts = context.ExecuteAsync <Product, IProduct>(dQuery).Result; updatedProducts.CurrentPage.Count.Should().Be(6); // the 'Id' and 'Name' properties must be set updatedProducts.CurrentPage[5].Id.Should().Be(6); updatedProducts.CurrentPage[5].Name.Should().Be(newName); // the 'Price' and 'Category' properties must not be set updatedProducts.CurrentPage[5].Price.Should().Be(0); updatedProducts.CurrentPage[5].Category.Should().BeNull(); } }
public void When_given_two_GetString_classes_they_both_return_the_hard_coded_result() { var @namespace1 = "_" + Any.AlphanumericString(1, 10); var typeName1 = "_" + Any.AlphanumericString(1, 10); var expectedSource1 = "_" + Any.AlphanumericString(1, 10); var @namespace2 = "_" + Any.AlphanumericString(1, 10); var typeName2 = "_" + Any.AlphanumericString(1, 10); var expectedSource2 = "_" + Any.AlphanumericString(1, 10); var proxySource1 = CodeSamples.GetStringSource(@namespace1, typeName1, expectedSource1); var proxySource2 = CodeSamples.GetStringSource(@namespace2, typeName2, expectedSource2); var asm = CompileText(null, proxySource1 + proxySource2); GetValue <string>(asm, "GetString", typeName1, @namespace1) .Should().Be(expectedSource1); GetValue <string>(asm, "GetString", typeName2, @namespace2) .Should().Be(expectedSource2); asm.GetNamespaces() .ShouldAllBeEquivalentTo(new[] { @namespace1, @namespace2 }); }
public override async Task When_a_clock_is_advanced_then_commands_are_not_triggered_that_have_not_become_due() { // arrange var shipmentId = Any.AlphanumericString(8, 8); var order = CommandSchedulingTests_EventSourced.CreateOrder(); order.Apply(new ShipOn(shipDate: Clock.Now().AddMonths(2).Date) { ShipmentId = shipmentId }); await Save(order); // act await AdvanceClock(by : TimeSpan.FromDays(30)); //assert order = await Get <Order>(order.Id); var lastEvent = order.Events().Last(); lastEvent.Should().BeOfType <CommandScheduled <Order> >(); }
public async Task When_an_exception_is_thrown_during_a_read_model_update_then_it_is_logged_on_its_bus() { var projector = new Projector <Order.ItemAdded> { OnUpdate = (work, e) => { throw new Exception("oops!"); } }; var itemAdded = new Order.ItemAdded { AggregateId = Any.Guid(), SequenceNumber = 1, ProductName = Any.AlphanumericString(10, 20), Price = Any.Decimal(0.01m), Quantity = 100 }; var errors = new List <Domain.EventHandlingError>(); using (var catchup = CreateReadModelCatchup(projector)) using (var db = EventStoreDbContext()) { db.Events.Add(itemAdded.ToStorableEvent()); db.SaveChanges(); catchup.EventBus.Errors.Subscribe(errors.Add); await catchup.Run(); } var error = errors.Single(e => e.AggregateId == itemAdded.AggregateId); error.SequenceNumber .Should() .Be(itemAdded.SequenceNumber); error.Event .SequenceNumber .Should() .Be(itemAdded.SequenceNumber); }
public Given_an_OdcmClass_Entity_Collection_AddAsync_Method() { Init(null, true); _addAsyncMethod = CollectionInterface.GetMethod("Add" + Class.Name + "Async", PermissiveBindingFlags, null, new[] { ConcreteInterface, typeof(bool) }, null); _entity = new object(); _itemToAdd = ConstructConcreteInstance(); _entityName = Any.AlphanumericString(1); _path = Any.String() + "/" + _entityName; _dscwMock = new Mock <DataServiceContextWrapper>(MockBehavior.Strict); _saveChangesAsyncReturnValue = null; ConfigureCollectionInstance(); }
public void SetUp() { sensorName = Any.AlphanumericString(10, 20); }
public void SetUp() { configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Default; sensorName = Any.AlphanumericString(10, 20); }