Exemplo n.º 1
0
        public void CreateFiltersOmitSpecimenInstances()
        {
            // Fixture setup
            var request         = typeof(IEnumerable <int>);
            var expectedRequest = new MultipleRequest(typeof(int));

            var enumerable = new object[]
            {
                1,
                new OmitSpecimen(),
                3
            };
            var context = new DelegatingSpecimenContext
            {
                OnResolve = r => expectedRequest.Equals(r) ? (object)enumerable : new NoSpecimen()
            };

            var sut = new EnumerableRelay();
            // Exercise system
            var actual = sut.Create(request, context);
            // Verify outcome
            var iter = Assert.IsAssignableFrom <IEnumerable <int> >(actual);

            Assert.True(
                enumerable.OfType <int>().SequenceEqual(iter),
                "Actual sequence is not equal to expected sequence.");
            // Teardown
        }
        public void CreateFromMultipleRequestReturnsCorrectResult(
            Type itemType,
            int arrayLength)
        {
            // Fixture setup
            var sut     = new MultipleToEnumerableRelay();
            var context = new DelegatingSpecimenContext
            {
                OnResolve = r =>
                {
                    Assert.Equal(
                        typeof(IEnumerable <>).MakeGenericType(itemType),
                        r);
                    return(Array.CreateInstance((Type)itemType, arrayLength));
                }
            };
            // Exercise system
            var request = new MultipleRequest(itemType);
            var actual  = sut.Create(request, context);

            // Verify outcome
            Assert.IsAssignableFrom(
                typeof(IEnumerable <>).MakeGenericType(itemType),
                actual);
            var enumerable =
                Assert.IsAssignableFrom <System.Collections.IEnumerable>(actual);

            Assert.Equal(arrayLength, enumerable.Cast <object>().Count());
            // Teardown
        }
        public void CreateFromMultipleSeededRequestReturnsCorrectResult(
            Type itemType,
            object seed,
            int arrayLength)
        {
            // Arrange
            var sut     = new MultipleToEnumerableRelay();
            var context = new DelegatingSpecimenContext
            {
                OnResolve = r =>
                {
                    Assert.Equal(
                        typeof(IEnumerable <>).MakeGenericType(itemType),
                        r);
                    return(Array.CreateInstance((Type)itemType, arrayLength));
                }
            };
            // Act
            var request = new MultipleRequest(new SeededRequest(itemType, seed));
            var actual  = sut.Create(request, context);

            // Assert
            Assert.IsAssignableFrom(
                typeof(IEnumerable <>).MakeGenericType(itemType),
                actual);
            var enumerable =
                Assert.IsAssignableFrom <System.Collections.IEnumerable>(actual);

            Assert.Equal(arrayLength, enumerable.Cast <object>().Count());
        }
 public void CreateFromMultipleRequestReturnsCorrectResult(
     Type itemType,
     int arrayLength)
 {
     // Fixture setup
     var sut = new MultipleToEnumerableRelay();
     var context = new DelegatingSpecimenContext
     {
         OnResolve = r =>
         {
             Assert.Equal(
                 typeof(IEnumerable<>).MakeGenericType(itemType),
                 r);
             return Array.CreateInstance((Type)itemType, arrayLength);
         }
     };
     // Exercise system
     var request = new MultipleRequest(itemType);
     var actual = sut.Create(request, context);
     // Verify outcome
     Assert.IsAssignableFrom(
         typeof(IEnumerable<>).MakeGenericType(itemType),
         actual);
     var enumerable =
         Assert.IsAssignableFrom<System.Collections.IEnumerable>(actual);
     Assert.Equal(arrayLength, enumerable.Cast<object>().Count());
     // Teardown
 }
        public List <Message <T> > MultipleRequest(MultipleRequest <T> request)
        {
            try
            {
                CheckRequest(request);

                var retVal = new List <Message <T> >(request.Count);

                for (var i = 0; i < request.Count; i++)
                {
                    if (streamData[request.Topic].Count > request.Offset)
                    {
                        retVal.Add(ReadRecord(request));
                        request.Offset++;
                    }
                    else
                    {
                        break;
                    }
                }

                return(retVal);
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error while processing stream request: {e.Message}");
                return(null);
            }
        }
        private static object GetInnerRequest(MultipleRequest multipleRequest)
        {
            var seededRequest = multipleRequest.Request as SeededRequest;
            if (seededRequest == null)
                return multipleRequest.Request;

            return seededRequest.Request;
        }
Exemplo n.º 7
0
 public void SutIsEquatable()
 {
     // Fixture setup
     // Exercise system
     var sut = new MultipleRequest(new object());
     // Verify outcome
     Assert.IsAssignableFrom<IEquatable<MultipleRequest>>(sut);
     // Teardown
 }
        public void SutIsEquatable()
        {
            // Arrange
            // Act
            var sut = new MultipleRequest(new object());

            // Assert
            Assert.IsAssignableFrom <IEquatable <MultipleRequest> >(sut);
        }
Exemplo n.º 9
0
        public void SutIsEquatable()
        {
            // Fixture setup
            // Exercise system
            var sut = new MultipleRequest(new object());

            // Verify outcome
            Assert.IsAssignableFrom <IEquatable <MultipleRequest> >(sut);
            // Teardown
        }
        public void GetHashCodeReturnsCorrectResult()
        {
            // Arrange
            var sut = new MultipleRequest(new object());
            // Act
            var result = sut.GetHashCode();
            // Assert
            var expectedResult = sut.Request.GetHashCode();

            Assert.Equal(expectedResult, result);
        }
Exemplo n.º 11
0
 public void SutDoesNotEqualAnonymousObject()
 {
     // Fixture setup
     var sut = new MultipleRequest(new object());
     object anonymousObject = new FileStyleUriParser();
     // Exercise system
     var result = sut.Equals(anonymousObject);
     // Verify outcome
     Assert.False(result, "Equals");
     // Teardown
 }
Exemplo n.º 12
0
 public void RequestIsCorrect()
 {
     // Fixture setup
     var expectedRequest = new object();
     var sut = new MultipleRequest(expectedRequest);
     // Exercise system
     var result = sut.Request;
     // Verify outcome
     Assert.Equal(expectedRequest, result);
     // Teardown
 }
Exemplo n.º 13
0
 public void SutDoesNotEqualOtherObjectWhenRequestDiffers()
 {
     // Fixture setup
     var sut = new MultipleRequest(new object());
     object other = new MultipleRequest(new object());
     // Exercise system
     var result = sut.Equals(other);
     // Verify outcome
     Assert.False(result, "Equals");
     // Teardown
 }
        public void SutDoesNotEqualAnonymousObject()
        {
            // Arrange
            var    sut             = new MultipleRequest(new object());
            object anonymousObject = new ConcreteType();
            // Act
            var result = sut.Equals(anonymousObject);

            // Assert
            Assert.False(result, "Equals");
        }
        public void SutDoesNotEqualNullSut()
        {
            // Arrange
            var             sut   = new MultipleRequest(new object());
            MultipleRequest other = null;
            // Act
            var result = sut.Equals(other);

            // Assert
            Assert.False(result, "Equals");
        }
        public void SutDoesNotEqualOtherSutWhenRequestDiffers()
        {
            // Arrange
            var sut   = new MultipleRequest(new object());
            var other = new MultipleRequest(new object());
            // Act
            var result = sut.Equals(other);

            // Assert
            Assert.False(result, "Equals");
        }
        public void RequestIsCorrect()
        {
            // Arrange
            var expectedRequest = new object();
            var sut             = new MultipleRequest(expectedRequest);
            // Act
            var result = sut.Request;

            // Assert
            Assert.Equal(expectedRequest, result);
        }
Exemplo n.º 18
0
        public void SutDoesNotEqualAnonymousObject()
        {
            // Fixture setup
            var    sut             = new MultipleRequest(new object());
            object anonymousObject = new ConcreteType();
            // Exercise system
            var result = sut.Equals(anonymousObject);

            // Verify outcome
            Assert.False(result, "Equals");
            // Teardown
        }
 public List <Message <T> > MultipleRequest(MultipleRequest <T> request)
 {
     try
     {
         return(brokerRequestProxy.MultipleRequest(request));
     }
     catch (Exception e)
     {
         Console.WriteLine($"Exception while sending request: {e.Message}");
         return(null);
     }
 }
        public void SutEqualsOtherSutWhenRequestMatches()
        {
            // Arrange
            var request = new object();
            var sut     = new MultipleRequest(request);
            var other   = new MultipleRequest(request);
            // Act
            var result = sut.Equals(other);

            // Assert
            Assert.True(result, "Equals");
        }
Exemplo n.º 21
0
 public List <Message <T> > MultipleRequest(MultipleRequest <T> request)
 {
     try
     {
         return(proxy.MultipleRequest(request));
     }
     catch (Exception e)
     {
         Console.WriteLine($"Exception while processing stream request: {e.Message}");
         return(null);
     }
 }
Exemplo n.º 22
0
        public void GetHashCodeReturnsCorrectResult()
        {
            // Fixture setup
            var sut = new MultipleRequest(new object());
            // Exercise system
            var result = sut.GetHashCode();
            // Verify outcome
            var expectedResult = sut.Request.GetHashCode();

            Assert.Equal(expectedResult, result);
            // Teardown
        }
Exemplo n.º 23
0
        public void RequestIsCorrect()
        {
            // Fixture setup
            var expectedRequest = new object();
            var sut             = new MultipleRequest(expectedRequest);
            // Exercise system
            var result = sut.Request;

            // Verify outcome
            Assert.Equal(expectedRequest, result);
            // Teardown
        }
Exemplo n.º 24
0
        public void SutDoesNotEqualOtherObjectWhenRequestDiffers()
        {
            // Fixture setup
            var    sut   = new MultipleRequest(new object());
            object other = new MultipleRequest(new object());
            // Exercise system
            var result = sut.Equals(other);

            // Verify outcome
            Assert.False(result, "Equals");
            // Teardown
        }
Exemplo n.º 25
0
        public void SutEqualsOtherSutWhenRequestMatches()
        {
            // Fixture setup
            var request = new object();
            var sut     = new MultipleRequest(request);
            var other   = new MultipleRequest(request);
            // Exercise system
            var result = sut.Equals(other);

            // Verify outcome
            Assert.True(result, "Equals");
            // Teardown
        }
Exemplo n.º 26
0
        public void CreateWithArrayRequestReturnsCorrectResult(Type request, Type itemType)
        {
            // Fixture setup
            var expectedRequest = new MultipleRequest(itemType);
            object expectedResult = Array.CreateInstance(itemType, 0);
            var context = new DelegatingSpecimenContext { OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen(r) };

            var sut = new ArrayRelay();
            // Exercise system
            var result = sut.Create(request, context);
            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
Exemplo n.º 27
0
        public void AddManyFillsDictionary()
        {
            // Fixture setup
            var dictionary = new Dictionary<int, string>();

            var expectedRequest = new MultipleRequest(typeof(KeyValuePair<int, string>));
            var expectedResult = Enumerable.Range(1, 3).Select(i => new KeyValuePair<int, string>(i, i.ToString()));
            var context = new DelegatingSpecimenContext { OnResolve = r => expectedRequest.Equals(r) ? (object)expectedResult : new NoSpecimen(r) };
            // Exercise system
            DictionaryFiller.AddMany(dictionary, context);
            // Verify outcome
            Assert.True(expectedResult.SequenceEqual(dictionary));
            // Teardown
        }
        public void CreateFromMultipleRequestWithNonTypeRequestReturnsCorrectResult(
            object innerRequest)
        {
            // Arrange
            var sut     = new MultipleToEnumerableRelay();
            var request = new MultipleRequest(innerRequest);
            // Act
            var dummyContext = new DelegatingSpecimenContext();
            var actual       = sut.Create(request, dummyContext);
            // Assert
            var expected = new NoSpecimen();

            Assert.Equal(expected, actual);
        }
Exemplo n.º 29
0
        public void CreateWithEnumerableRequestReturnsCorrectResult(Type request, Type itemType)
        {
            // Fixture setup
            var expectedRequest = new MultipleRequest(itemType);
            object contextResult = Enumerable.Empty<object>();
            var context = new DelegatingSpecimenContext { OnResolve = r => expectedRequest.Equals(r) ? contextResult : new NoSpecimen(r) };

            var sut = new EnumerableRelay();
            // Exercise system
            var result = sut.Create(request, context);
            // Verify outcome
            Assert.NotNull(result);
            // Teardown
        }
        public void CreateFromMultipleRequestWithNonTypeRequestReturnsCorrectResult(
            object innerRequest)
        {
            // Fixture setup
            var sut     = new MultipleToEnumerableRelay();
            var request = new MultipleRequest(innerRequest);
            // Exercise system
            var dummyContext = new DelegatingSpecimenContext();
            var actual       = sut.Create(request, dummyContext);
            // Verify outcome
            var expected = new NoSpecimen(request);

            Assert.Equal(expected, actual);
            // Teardown
        }
Exemplo n.º 31
0
        public void DoesNotThrowWithDuplicateEntries()
        {
            // Arrange
            var dictionary = new Dictionary <int, string>();

            var request  = new MultipleRequest(typeof(KeyValuePair <int, string>));
            var sequence = Enumerable.Repeat(0, 3).Select(i => new KeyValuePair <int, string>(i, i.ToString()));
            var context  = new DelegatingSpecimenContext {
                OnResolve = r => request.Equals(r) ? (object)sequence : new NoSpecimen()
            };

            var sut = new DictionaryFiller();

            // Act & Assert
            Assert.Null(Record.Exception(() => sut.Execute(dictionary, context)));
        }
Exemplo n.º 32
0
        public void CreateWithEnumerableRequestReturnsCorrectResult(Type request, Type itemType)
        {
            // Arrange
            var    expectedRequest = new MultipleRequest(itemType);
            object contextResult   = Enumerable.Empty <object>();
            var    context         = new DelegatingSpecimenContext {
                OnResolve = r => expectedRequest.Equals(r) ? contextResult : new NoSpecimen()
            };

            var sut = new EnumerableRelay();
            // Act
            var result = sut.Create(request, context);

            // Assert
            Assert.NotNull(result);
        }
        public void CreateFromMultipleRequestWithNonTypeRequestReturnsCorrectResult(
            object innerRequest)
        {
            // Fixture setup
            var sut = new MultipleToEnumerableRelay();
            var request = new MultipleRequest(innerRequest);
            // Exercise system
            var dummyContext = new DelegatingSpecimenContext();
            var actual = sut.Create(request, dummyContext);
            // Verify outcome
#pragma warning disable 618
            var expected = new NoSpecimen(request);
#pragma warning restore 618
            Assert.Equal(expected, actual);
            // Teardown
        }
Exemplo n.º 34
0
        public void CreateConvertsEnumerableToArray()
        {
            // Fixture setup
            var request = typeof(int[]);
            var expectedRequest = new MultipleRequest(typeof(int));
            var enumerable = Enumerable.Range(1, 3);
            var context = new DelegatingSpecimenContext { OnResolve = r => expectedRequest.Equals(r) ? (object)enumerable : new NoSpecimen(r) };

            var sut = new ArrayRelay();
            // Exercise system
            var result = sut.Create(request, context);
            // Verify outcome
            var a = Assert.IsAssignableFrom<int[]>(result);
            Assert.True(enumerable.SequenceEqual(a));
            // Teardown
        }
Exemplo n.º 35
0
        public void CreateWithArrayRequestReturnsCorrectResult(Type request, Type itemType)
        {
            // Arrange
            var    expectedRequest = new MultipleRequest(itemType);
            object expectedResult  = Array.CreateInstance(itemType, 0);
            var    context         = new DelegatingSpecimenContext {
                OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen()
            };

            var sut = new ArrayRelay();
            // Act
            var result = sut.Create(request, context);

            // Assert
            Assert.Equal(expectedResult, result);
        }
Exemplo n.º 36
0
        public void CreateWithArrayRequestReturnsCorrectResult(Type request, Type itemType)
        {
            // Fixture setup
            var    expectedRequest = new MultipleRequest(itemType);
            object expectedResult  = Array.CreateInstance(itemType, 0);
            var    context         = new DelegatingSpecimenContext {
                OnResolve = r => expectedRequest.Equals(r) ? expectedResult : new NoSpecimen()
            };

            var sut = new ArrayRelay();
            // Exercise system
            var result = sut.Create(request, context);

            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
Exemplo n.º 37
0
        public void AddManyFillsDictionary()
        {
            // Fixture setup
            var dictionary = new Dictionary <int, string>();

            var expectedRequest = new MultipleRequest(typeof(KeyValuePair <int, string>));
            var expectedResult  = Enumerable.Range(1, 3).Select(i => new KeyValuePair <int, string>(i, i.ToString()));
            var context         = new DelegatingSpecimenContext {
                OnResolve = r => expectedRequest.Equals(r) ? (object)expectedResult : new NoSpecimen(r)
            };

            // Exercise system
            DictionaryFiller.AddMany(dictionary, context);
            // Verify outcome
            Assert.True(expectedResult.SequenceEqual(dictionary));
            // Teardown
        }
Exemplo n.º 38
0
        public void CreateWithEnumerableRequestReturnsCorrectResult(Type request, Type itemType)
        {
            // Fixture setup
            var    expectedRequest = new MultipleRequest(itemType);
            object contextResult   = Enumerable.Empty <object>();
            var    context         = new DelegatingSpecimenContext {
                OnResolve = r => expectedRequest.Equals(r) ? contextResult : new NoSpecimen()
            };

            var sut = new EnumerableRelay();
            // Exercise system
            var result = sut.Create(request, context);

            // Verify outcome
            Assert.NotNull(result);
            // Teardown
        }
Exemplo n.º 39
0
            public void AddManyFillsDictionary()
            {
                // Arrange
                var dictionary = new Dictionary <int, string>();

                var expectedRequest = new MultipleRequest(typeof(KeyValuePair <int, string>));
                var expectedResult  = Enumerable.Range(1, 3).Select(i => new KeyValuePair <int, string>(i, i.ToString()));
                var context         = new DelegatingSpecimenContext
                {
                    OnResolve = r => expectedRequest.Equals(r) ? (object)expectedResult : new NoSpecimen()
                };

                // Act
                DictionaryFiller.AddMany(dictionary, context);
                // Assert
                Assert.True(expectedResult.SequenceEqual(dictionary));
            }
        public void DoesNotThrowWithDuplicateEntries()
        {
            // Fixture setup
            var dictionary = new Dictionary <int, string>();

            var request  = new MultipleRequest(typeof(KeyValuePair <int, string>));
            var sequence = Enumerable.Repeat(0, 3).Select(i => new KeyValuePair <int, string>(i, i.ToString()));
            var context  = new DelegatingSpecimenContext {
                OnResolve = r => request.Equals(r) ? (object)sequence : new NoSpecimen(r)
            };

            var sut = new DictionaryFiller();

            // Exercise system & Verify outcome
            Assert.DoesNotThrow(() => sut.Execute(dictionary, context));
            // Teardown
        }
Exemplo n.º 41
0
        public void CreateConvertsEnumerableToArray()
        {
            // Arrange
            var request         = typeof(int[]);
            var expectedRequest = new MultipleRequest(typeof(int));
            var enumerable      = Enumerable.Range(1, 3);
            var context         = new DelegatingSpecimenContext {
                OnResolve = r => expectedRequest.Equals(r) ? (object)enumerable : new NoSpecimen()
            };

            var sut = new ArrayRelay();
            // Act
            var result = sut.Create(request, context);
            // Assert
            var a = Assert.IsAssignableFrom <int[]>(result);

            Assert.True(enumerable.SequenceEqual(a));
        }
Exemplo n.º 42
0
        public void CreateConvertsEnumerableToCorrectGenericType()
        {
            // Fixture setup
            var request = typeof(IEnumerable<int>);
            var expectedRequest = new MultipleRequest(typeof(int));
            var enumerable = Enumerable.Range(1, 3).Cast<object>();
#pragma warning disable 618
            var context = new DelegatingSpecimenContext { OnResolve = r => expectedRequest.Equals(r) ? (object)enumerable : new NoSpecimen(r) };
#pragma warning restore 618

            var sut = new EnumerableRelay();
            // Exercise system
            var result = sut.Create(request, context);
            // Verify outcome
            var e = Assert.IsAssignableFrom<IEnumerable<int>>(result);
            Assert.True(enumerable.Cast<int>().SequenceEqual(e));
            // Teardown
        }
Exemplo n.º 43
0
 public void SutEqualsOtherSutWhenRequestMatches()
 {
     // Fixture setup
     var request = new object();
     var sut = new MultipleRequest(request);
     var other = new MultipleRequest(request);
     // Exercise system
     var result = sut.Equals(other);
     // Verify outcome
     Assert.True(result, "Equals");
     // Teardown
 }
Exemplo n.º 44
0
 public void GetHashCodeReturnsCorrectResult()
 {
     // Fixture setup
     var sut = new MultipleRequest(new object());
     // Exercise system
     var result = sut.GetHashCode();
     // Verify outcome
     var expectedResult = sut.Request.GetHashCode();
     Assert.Equal(expectedResult, result);
     // Teardown
 }
Exemplo n.º 45
0
        public void CreateFiltersOmitSpecimenInstances()
        {
            // Fixture setup
            var request = typeof(IEnumerable<int>);
            var expectedRequest = new MultipleRequest(typeof(int));

            var enumerable = new object[]
            {
                1,
                new OmitSpecimen(),
                3
            };
            var context = new DelegatingSpecimenContext
            {
                OnResolve = r => expectedRequest.Equals(r) ? (object)enumerable : new NoSpecimen(r)
            };

            var sut = new EnumerableRelay();
            // Exercise system
            var actual = sut.Create(request, context);
            // Verify outcome
            var iter = Assert.IsAssignableFrom<IEnumerable<int>>(actual);
            Assert.True(
                enumerable.OfType<int>().SequenceEqual(iter),
                "Actual sequence is not equal to expected sequence.");
            // Teardown
        }
Exemplo n.º 46
0
        public void CreateWithManyRequestReturnsCorrectResult()
        {
            // Fixture setup
            var request = new MultipleRequest(new object());
            var count = 7;
            var expectedTranslation = new FiniteSequenceRequest(request.Request, 7);
            var expectedResult = new object();
            var container = new DelegatingSpecimenContext { OnResolve = r => expectedTranslation.Equals(r) ? expectedResult : new NoSpecimen(r) };

            var sut = new MultipleRelay { Count = count };
            // Exercise system
            var result = sut.Create(request, container);
            // Verify outcome
            Assert.Equal(expectedResult, result);
            // Teardown
        }
        public void DoesNotThrowWithDuplicateEntries()
        {
            // Fixture setup
            var dictionary = new Dictionary<int, string>();

            var request = new MultipleRequest(typeof(KeyValuePair<int, string>));
            var sequence = Enumerable.Repeat(0, 3).Select(i => new KeyValuePair<int, string>(i, i.ToString()));
            var context = new DelegatingSpecimenContext { OnResolve = r => request.Equals(r) ? (object)sequence : new NoSpecimen(r) };

            var sut = new DictionaryFiller();
            // Exercise system & Verify outcome
            Assert.DoesNotThrow(() => sut.Execute(dictionary, context));
            // Teardown
        }