static IntervalTimePerTimeValuesAttribute()
        {
            var values = new List<IQuantity>();

            var times = new[]
            {
                //TODO: ... however, us, ms, s, min, hr, are not unreasonable to expect ...
                T.Microsecond,
                T.Millisecond,
                T.Second,
                T.Minute,
                T.Hour,
                ////TODO: we do not care about Days or Weeks for purposes of these tests...
                //T.Day,
                //T.Week,
            };

            // TODO: TBD: Avoid scaling too absurdly: may want to be more selective than this...
            var length = times.Length - 2;

            // TODO: TBD: Could also vary the value itself, but this will do for starters...
            const double value = 1e2;

            var first = times.Take(length).ToArray();
            var second = times.Reverse().Take(length).ToArray();

            values.AddRange(from x in first from y in second select new Quantity(value, x, y.Invert()));
            values.AddRange(from y in first from x in second select new Quantity(value, x, y.Invert()));

            Values = values.OfType<object>().ToArray();
        }
Exemple #2
0
 public void ShouldBehavior()
 {
     var items = new List<object>();
     items.Add("Hello");
     items.Add(5);
     string item = items.OfType<string>().First();
     Assert.That(item, Is.EqualTo("Hello"));
 }
		public void OfType_LinqExt ()
		{
			// Filter out those which are note od typw double
			var sampleIntNumbers = new List<object> (){ 1,2,3,4,5,6m,7,8m,9,10};
			var sampleDecimalNumbers = sampleIntNumbers.OfType<decimal> ().ToList ();

			Assert.AreEqual (2, sampleDecimalNumbers.Count ());
	
			Assert.IsInstanceOfType (typeof(List<decimal>), sampleDecimalNumbers);
			Assert.IsInstanceOfType (typeof(decimal), sampleDecimalNumbers.First ());
		}
        public void SetUp()
        {
            var configurationSettings = new List<IConfigurationSetting>();

            ConfigurationConfigurator.RegisterConfigurationSettings()
                                     .FromAssemblies(Assembly.GetExecutingAssembly())
                                     .RegisterWithContainer(configurationSettings.Add)
                                     .AllowConfigurationEntriesThatDoNotHaveSettingsClasses(false)
                                     .WithCustomValueParsers(new PersonNameValueParser())
                                     .ExcludeSettingKeys("IgnoredSetting")
                                     .DoYourThing();

            _somePersonSetting = configurationSettings.OfType<SomePersonSetting>().Single();
        }
        public void IndexShouldRenderViewIndex()
        {
            var contents = new List<Content>
                {
                    new TextContent { UrlName = HomeController.Shopfront }
                }.AsQueryable();

            contentRepository.Expect(cr => cr.GetAll()).Return(contents);

            homeController.Index()
                .ReturnsViewResult()
                .ForView("Index")
                .WithModel<CmsViewData>()
                .AssertAreSame(
                    contents.OfType<ITextContent>().First(), 
                    vd => vd.TextContent);

        }
        public void Index_ShouldRenderTopContentWithTopPageView()
        {
            const string urlName = "home_page";

            var contents = new List<Content>
            {
                new TopContent { UrlName = "home_page" }
            }.AsQueryable();

            contentRepository.Expect(cr => cr.GetAll()).Return(contents);

            cmsController.Index(urlName)
                .ReturnsViewResult()
                .ForView("TopPage")
                .WithModel<CmsViewData>()
                .AssertAreSame(
                    contents.OfType<ITextContent>().First(), vd => vd.TextContent);

        }
        static TimePerStepValuesAttribute()
        {
            var values = new List<IQuantity>();

            var times = new[]
            {
                T.Microsecond,
                T.Millisecond,
                T.Second,
                T.Minute,
                T.Hour,
                //// Day and week are way too extreme for purposes of these tests.
                //T.Day,
                //T.Week,
            };

            const double value = 1e1;

            values.AddRange(from t in times select new Quantity(value, t));

            Values = values.OfType<object>().ToArray();
        }
Exemple #8
0
        public void OfTypeQueryReuse()
        {
            List<int> data = new List<int> { 1, 2 };
            IEnumerable<object> enumerable = data.OfType<object>();

            enumerable.AssertEqual(1, 2);

            data.Add(3);
            enumerable.AssertEqual(1, 2, 3);
        }
        private static FeatureCoverage GetTimeDependentFeatureCoverage()
        {
            IList<SimpleFeature> features = new List<SimpleFeature>
                                                {
                                                    new SimpleFeature(0, new Point(0, 0)),
                                                    new SimpleFeature(1, new Point(1, 1)),
                                                    new SimpleFeature(2, new Point(2, 2))
                                                };

            var coverage = FeatureCoverage.GetTimeDependentFeatureCoverage<SimpleFeature>();
            
            // set values of feature a variable
            coverage.Features.AddRange(features.OfType<IFeature>());
            coverage.FeatureVariable.SetValues(features);
            return coverage;
        }
        public void UnityCanResolveEnumerableOfTypesRegisteredInUnityTest()
        {
            // Setup
            var unityContainer = new UnityContainer();

            // Add composition support for unity
            unityContainer.AddNewExtension<LazySupportExtension>();

            Component1.InstanceCount = 0;
            Component2.InstanceCount = 0;

            unityContainer.RegisterType<IComponent, Component1>("component1");
            unityContainer.RegisterType<IComponent, Component2>("component2");
            unityContainer.RegisterType<IComponent, Component3>();

            var collectionOfLazyUnityComponents = unityContainer.Resolve<IEnumerable<IComponent>>();
            Assert.That(collectionOfLazyUnityComponents, Is.Not.Null);

            Assert.That(Component1.InstanceCount, Is.EqualTo(1));
            Assert.That(Component2.InstanceCount, Is.EqualTo(1));

            var list = new List<IComponent>(collectionOfLazyUnityComponents);
            Assert.That(list.Count, Is.EqualTo(3));

            Assert.That(list.OfType<Component1>().Count(), Is.EqualTo(1));
            Assert.That(list.OfType<Component2>().Count(), Is.EqualTo(1));
            Assert.That(list.OfType<Component3>().Count(), Is.EqualTo(1));
        }
Exemple #11
0
        public void ContainersAreNestedAndSorted()
        {
            Type itemType = typeof(Definitions.ItemWithNestedContainers);
            IList<IEditable> editables = new List<IEditable>();
            IList<IEditableContainer> containers = explorer.Find<IEditableContainer>(itemType);
            HierarchyNode<IContainable> rootContainer = hierarchyBuilder.Build(containers.OfType<IContainable>(), editables.OfType<IContainable>());

            var first = rootContainer.Children[0];//.GetContained(null)[0] as IEditableContainer;
            Assert.IsNotNull(first.Current);
            Assert.AreSame(first.Current, containers[1]);
            Assert.AreEqual(3, first.Children.Count);//.GetContained(null).Count);

            var inside3 = first.Children[0];//.GetContained(null)[0] as IEditableContainer;
            Assert.IsNotNull(inside3.Current);
            Assert.AreSame(inside3.Current, containers[0]);
            Assert.AreEqual(0, inside3.Children.Count);//.GetContained(null).Count);

            var inside1 = first.Children[1];//.GetContained(null)[1] as IEditableContainer;
            Assert.IsNotNull(inside1.Current);
            Assert.AreSame(inside1.Current, containers[2]);
            Assert.AreEqual(1, inside1.Children.Count);//.GetContained(null).Count);

            var inside2 = first.Children[2];//.GetContained(null)[2] as IEditableContainer;
            Assert.IsNotNull(inside2.Current);
            Assert.AreSame(inside2.Current, containers[3]);
            Assert.AreEqual(0, inside2.Children.Count);//.GetContained(null).Count);
        }
        public void UnityCanResolveEnumerableOfTypesRegisteredInUnityAndMefTest()
        {
            // Setup
            var unityContainer = new UnityContainer();
            var assemblyCatalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());

            MixedComponent1.InstanceCount = 0;
            MixedComponent2.InstanceCount = 0;
            MixedComponent5.InstanceCount = 0;

            // Add composition support for unity
            unityContainer.AddExtension(new CompositionIntegration(true));
            unityContainer.Configure<CompositionIntegration>().Catalogs.Add(assemblyCatalog);

            unityContainer.RegisterType<IMixedComponent, MixedComponent1>("component1");
            unityContainer.RegisterType<IMixedComponent, MixedComponent2>("component2");
            unityContainer.RegisterType<IMixedComponent, MixedComponent3>();

            var collectionOfLazyUnityComponents = unityContainer.Resolve<IEnumerable<IMixedComponent>>();
            Assert.That(collectionOfLazyUnityComponents, Is.Not.Null);

            Assert.That(MixedComponent1.InstanceCount, Is.EqualTo(1));
            Assert.That(MixedComponent2.InstanceCount, Is.EqualTo(1));
            Assert.That(MixedComponent5.InstanceCount, Is.EqualTo(1));

            var list = new List<IMixedComponent>(collectionOfLazyUnityComponents);
            Assert.That(list.Count, Is.EqualTo(5));
            Assert.That(list.OfType<MixedComponent1>().Count(), Is.EqualTo(1));
            Assert.That(list.OfType<MixedComponent2>().Count(), Is.EqualTo(1));
            Assert.That(list.OfType<MixedComponent3>().Count(), Is.EqualTo(1));
            Assert.That(list.OfType<MixedComponent4>().Count(), Is.EqualTo(1));
            Assert.That(list.OfType<MixedComponent5>().Count(), Is.EqualTo(1));
        }
Exemple #13
0
 public void OriginalSourceReturnedForSequenceOfCorrectNonNullableValueType()
 {
     IEnumerable ints = new List<int>();
     Assert.AreSame(ints, ints.OfType<int>());
 }
Exemple #14
0
        public void InvalidContainerReference_IsIgnored()
        {
            Type itemType = typeof(N2.Tests.Definitions.Definitions.ItemWithNestedContainers);
            IList<IEditable> editables = new List<IEditable>();
            IList<IEditableContainer> containers = explorer.Find<IEditableContainer>(itemType);
            containers.RemoveAt(2); // inside1

            Assert.DoesNotThrow(() => hierarchyBuilder.Build(containers.OfType<IContainable>(), editables.OfType<IContainable>()));
        }
Exemple #15
0
 public void OriginalSourceNotReturnedForNullableValueTypes()
 {
     IEnumerable nullableInts = new List<int?>();
     Assert.AreNotSame(nullableInts, nullableInts.OfType<int?>());
 }
Exemple #16
0
 public void OriginalSourceNotReturnedForReferenceTypes()
 {
     IEnumerable strings = new List<string>();
     Assert.AreNotSame(strings, strings.OfType<string>());
 }
Exemple #17
0
				public void Draw(List<DrawableEntity> visibleEntities)
				{
					foreach (var triangle in visibleEntities.OfType<Triangle>())
						drawing.AddGeometry(triangle.geometry, triangle.material, Matrix.Identity);
				}
Exemple #18
0
			public void Draw(List<DrawableEntity> visibleEntities)
			{
				foreach (var sprite in visibleEntities.OfType<Sprite>())
					drawing.Add(sprite.Material, GetQuadVertices(sprite), new short[] { 0, 2, 1, 0, 3, 2 });
			}
 private static Comment CommentContaining(List<ISpecial> specials, string value)
 {
     var comment = specials.OfType<Comment>().FirstOrDefault(x => x.CommentText.Contains(value));
     if (comment == null)
         Assert.Inconclusive("There was no comment containing the text '" + value + "'.");
     return comment;
 }
Exemple #20
0
        public async void ShouldMonitorAllMessagesSentAndReceived()
        {
            FakeServiceEndpoint fakeServiceEndpoint = new FakeServiceEndpoint(typeof(ITestServiceMessage1));
            FakeServiceEndpoint fakeServer = new FakeServiceEndpoint(typeof(ITestServiceMessage2));

            List<IMessage> monitorReceived = new List<IMessage>();
            List<IMessage> monitorSent = new List<IMessage>();

            var monitorFactory = A.Fake<IMonitorFactory<IMessage>>();
            var monitor = A.Fake<IMonitor<IMessage>>();
            A.CallTo(() => monitor.MessageReceived(A<IMessage>._, A<TimeSpan>._)).Invokes(call =>
            {
                var message = call.GetArgument<IMessage>(0);
                Console.WriteLine("Received {0}", message);
                monitorReceived.Add(message);
            });
            A.CallTo(() => monitor.MessageSent(A<IMessage>._, A<TimeSpan>._)).Invokes(call =>
            {
                var message = call.GetArgument<IMessage>(0);
                Console.WriteLine("Sent {0}", message);
                monitorSent.Add(message);
            });
            A.CallTo(() => monitorFactory.Create(A<string>._)).Returns(monitor);

            IServiceBus serviceBus = ServiceBus.Configure()
                .WithEndpoint((IServiceEndpoint)fakeServiceEndpoint)
                .WithEndpoint((IServiceEndpointClient)fakeServer)
                .UsingMonitor(monitorFactory)
                .Create();

            List<Exception> exceptions = new List<Exception>();
            List<IMessage> serviceBusMessages = new List<IMessage>();
            serviceBus.Exceptions.Subscribe(exceptions.Add);
            serviceBus.Events.Subscribe(serviceBusMessages.Add);
            serviceBus.Commands.Subscribe(serviceBusMessages.Add);
            serviceBus.Requests.Subscribe(serviceBusMessages.Add);

            fakeServer.Commands.OfType<TestServiceCommand1>().Subscribe(async command => await fakeServer.PublishAsync(new TestServiceEvent2()));
            fakeServer.Requests.OfType<TestServiceRequest2>().Subscribe(async request => await fakeServer.ReplyAsync(request, new TestServiceResponse2()));

            serviceBus.GetResponses(new TestServiceRequest2()).Subscribe(serviceBusMessages.Add);
            await serviceBus.SendAsync(new TestServiceCommand2());
            await serviceBus.PublishAsync(new TestServiceEvent1());

            Assert.That(monitorSent.Count, Is.EqualTo(3));
            Assert.That(monitorSent.OfType<TestServiceCommand2>().Count(), Is.EqualTo(1));
            Assert.That(monitorSent.OfType<TestServiceEvent1>().Count(), Is.EqualTo(1));
            Assert.That(monitorSent.OfType<TestServiceRequest2>().Count(), Is.EqualTo(1));

            Assert.That(monitorReceived.Count, Is.EqualTo(1));
            Assert.That(monitorReceived.OfType<TestServiceResponse2>().Count(), Is.EqualTo(1));
        }
				public void Draw(List<DrawableEntity> visibleEntities)
				{
					foreach (var plane in visibleEntities.OfType<GroundPlane1X1>())
						drawing.AddGeometry(plane.geometry, plane.material, plane.Transform);
				}
Exemple #22
0
        public async void Session_Error_WhenInvalidAccessToken()
        {
            var errors = new List<Exception>();

            var user = await User.LoginAsync(Credentials.AccessToken("foo:bar", Guid.NewGuid().ToString(), isAdmin: true), new Uri("http://localhost:9080"));
            var serverUri = new Uri("realm://localhost:9080/foobar");
            using (var realm = Realm.GetInstance(new SyncConfiguration(user, serverUri)))
            {
                var session = realm.GetSession();
                session.Error += (o, e) => errors.Add(e.Exception);

                while (!errors.Any())
                {
                    await Task.Yield();
                }

                var sessionErrors = errors.OfType<SessionErrorException>().ToList();
                Assert.That(sessionErrors.Count, Is.EqualTo(1));
                Assert.That(sessionErrors[0].ErrorCode, Is.EqualTo(ErrorCode.BadUserAuthentication));
            }
        }
Exemple #23
0
 public void Draw(List<DrawableEntity> visibleEntities)
 {
     foreach (var sprite in visibleEntities.OfType<Sprite>())
         drawing.Add(sprite.material, QuadVertices, QuadIndices);
 }