public async Task When_Index_Invalid_IndexNotFoundException_Thrown(int index) { var bytes = new byte[] { 0x18, 0xd0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x40, 0x15, 0xfb, 0x22, 0x64, 0x3e, 0x29, 0x00, 0x00, 0x02, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x22, 0x62, 0x61, 0x72, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; var specs = new LookupInSpecBuilder().Get("foo").Exists("bar").Specs; var op = new MultiLookup <byte[]>("thekey", specs); op.OperationBuilderPool = new DefaultObjectPool <OperationBuilder>(new OperationBuilderPoolPolicy()); await op.SendAsync(new Mock <IConnection>().Object).ConfigureAwait(false); op.Read(new FakeMemoryOwner <byte>(bytes)); var result = new LookupInResult(op.GetCommandValues(), 0, TimeSpan.FromHours(1), new DefaultSerializer()); Assert.Throws <InvalidIndexException>(() => result.ContentAs <string>(index)); var value = result.ContentAs <string>(0); Assert.Equal("bar", value); }
public async Task ContentAs_WhenPathNotFound_ThrowsPathNotFoundException() { var bytes = new byte[] { 0x18, 0xd0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x40, 0x15, 0xfb, 0x22, 0x64, 0x3e, 0x29, 0x00, 0x00, 0x02, 0x00, 0x0a, // Index 0 = Success 0x00, 0x00, // Spec Body Length = 5 0x00, 0x00, 0x00, 0x05, // "bar" 0x22, 0x62, 0x61, 0x72, 0x22, // Index 1 = SubDocPathNotFound 0x00, 0xc0, // Spec Body Length = 0 0x00, 0x00, 0x00, 0x00 }; var specs = new LookupInSpecBuilder().Get("foo").Get("bar").Specs; var op = new MultiLookup <byte[]>("thekey", specs); op.OperationBuilderPool = new DefaultObjectPool <OperationBuilder>(new OperationBuilderPoolPolicy()); await op.SendAsync(new Mock <IConnection>().Object).ConfigureAwait(false); op.Read(new FakeMemoryOwner <byte>(bytes)); var result = new LookupInResult(op.GetCommandValues(), 0, TimeSpan.FromHours(1), new DefaultSerializer()); Assert.Throws <PathNotFoundException>(() => result.ContentAs <string>(1)); }
public void Test_ExpiryTime_Returns_Null_When_Expiry_Not_An_Option() { var getRequest = new MultiLookup <byte[]>("thekey", Array.Empty <LookupInSpec>()); getRequest.Read(new FakeMemoryOwner <byte>(_lookupInPacket)); var readResult = new GetResult(getRequest.ExtractBody(), new LegacyTranscoder(), new Mock <ILogger <GetResult> >().Object, _lookupInSpecs) { OpCode = OpCode.MultiLookup, Flags = getRequest.Flags, Header = getRequest.Header }; var expiryTime = readResult.ExpiryTime; Assert.Null(expiryTime); }
public void Test_Projection_With_Dictionary() { var getRequest = new MultiLookup <byte[]>("thekey", Array.Empty <LookupInSpec>()); getRequest.Read(new FakeMemoryOwner <byte>(_lookupInPacket)); var readResult = new GetResult(getRequest.ExtractBody(), new LegacyTranscoder(), new Mock <ILogger <GetResult> >().Object, _lookupInSpecs) { OpCode = OpCode.MultiLookup, Flags = getRequest.Flags, Header = getRequest.Header }; var result = readResult.ContentAs <Dictionary <string, dynamic> >(); Assert.Equal(result["name"], "Emmy-lou Dickerson"); }
public void Test_Projection_With_Poco() { var getRequest = new MultiLookup <byte[]>(); getRequest.Read(new FakeMemoryOwner <byte>(_lookupInPacket)); var readResult = new GetResult(getRequest.ExtractBody(), new LegacyTranscoder(), new Mock <ILogger <GetResult> >().Object, _lookupInSpecs) { OpCode = OpCode.MultiLookup, Flags = getRequest.Flags, Header = getRequest.Header }; var result = readResult.ContentAs <Person>(); Assert.Equal("Emmy-lou Dickerson", result.name); }