public void AddOperation_TypeDoesNotInheritdQuantityBase_ThrowsInvalidCastException() { // Arrange OperationStore store = new OperationStore(); Func <QuantityBase, QuantityBase, QuantityBase> operation = CreateMockOperation().Object.Operation; // Act/assert Assert.Throws <InvalidCastException>(() => store.AddOperation(typeof(string), typeof(int), operation)); }
public void AddOperation_ValidTypes_DoesNotThrow() { // Arrange OperationStore store = new OperationStore(); Func <QuantityBase, QuantityBase, QuantityBase> operation = CreateMockOperation().Object.Operation; // Act/assert Assert.DoesNotThrow(() => store.AddOperation(typeof(Quantity <float>), typeof(Quantity <float>), operation)); }
public void AddOperationTemplated_ExistingType_ThrowsArgumentException() { // Arrange OperationStore store = new OperationStore(); Func <QuantityBase, QuantityBase, QuantityBase> operation = CreateMockOperation().Object.Operation; store.AddOperation <Quantity <float>, Quantity <double> >(operation); // Act/assert Assert.Throws <ArgumentException>(() => store.AddOperation <Quantity <float>, Quantity <double> >(operation)); }
public void PerformOperation_CommutativeTypes_ThrowsInvalidOperationException() { // Arrange OperationStore store = new OperationStore(); var mockOperation = CreateMockOperation(); store.AddOperation <int, float>(mockOperation.Object.Operation); // Act/Assert Assert.Throws <InvalidOperationException>(() => store.PerformOperation(CreateStubQuantity <float>(), CreateStubQuantity <int>())); }
public void PerformOperation_RegisteredTypes_InvokesOperation() { // Arrange OperationStore store = new OperationStore(); var mockOperation = CreateMockOperation(); store.AddOperation <int, int>(mockOperation.Object.Operation); // Act store.PerformOperation(CreateStubQuantity <int>(), CreateStubQuantity <int>()); // Assert mockOperation.Verify(x => x.Operation(It.IsAny <QuantityBase>(), It.IsAny <QuantityBase>()), Times.Once()); }
public async Task Foo() { var entityStore = new EntityStore(); var operationStore = new OperationStore(entityStore.Watch()); var connection = new MockConnection(); var humanMapper = new HumanMapper(); var droidMapper = new DroidMapper(); var humanHeroMapper = new HumanHeroMapper( entityStore, humanMapper, droidMapper); var droidHeroMapper = new DroidHeroMapper( entityStore, humanMapper, droidMapper); var resultDataFactory = new GetHeroResultFactory( entityStore, humanHeroMapper, droidHeroMapper); var resultBuilder = new GetHeroResultBuilder( entityStore, ExtractEntityId, resultDataFactory, new SerializerResolver(new[] { new StringSerializer() })); var operationExecutor = new OperationExecutor <JsonDocument, GetHeroResult>( connection, () => resultBuilder, operationStore, ExecutionStrategy.NetworkOnly); GetHeroResult?result = null; var query = new GetHeroQuery(operationExecutor); query.Watch().Subscribe(c => { result = c.Data; }); await Task.Delay(1000); using (entityStore.BeginUpdate()) { DroidEntity entity = entityStore.GetOrCreate <DroidEntity>(new EntityId("Droid", "abc")); entity.Name = "C3-PO"; } await Task.Delay(1000); Assert.NotNull(result); EntityId ExtractEntityId(JsonElement obj) => new( obj.GetProperty("__typename").GetString() !, obj.GetProperty("id").GetString() !); }