Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version

Roslyn CTP: Three Introductory Projects

, 8 May 2012
An introduction to the Roslyn CTP
RoslynCTPSamples.zip
CodeGenerator
bin
Debug
CodeGenerator.vshost.exe
CodeGenerator.vshost.exe.manifest
Release
CodeGenerator.csproj.user
obj
x86
Debug
DesignTimeResolveAssemblyReferences.cache
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
EventImplementer
bin
Debug
Release
EventImplementer.csproj.user
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
source.extension.vsixmanifest
RoslynCTPLibrary
bin
Debug
RoslynCTPSamples.dll
RoslynCTPSamples.pdb
Release
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
RoslynCTPSamples.dll
RoslynCTPSamples.pdb
TempPE
Properties
CodeGeneratorTest
bin
Debug
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
RefactoringConsole
bin
Debug
RefactoringConsole.vshost.exe
RefactoringConsole.vshost.exe.manifest
obj
x86
Debug
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
RefactoringExtension
bin
Debug
Release
obj
Debug
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
RefactoringExtension.csproj.user
source.extension.vsixmanifest
using CodeGenerator;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;

namespace CodeGeneratorTest
{
    
    
    /// <summary>
    ///This is a test class for EnumerableExtensionsTest and is intended
    ///to contain all EnumerableExtensionsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class EnumerableExtensionsTest {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext {
            get {
                return testContextInstance;
            }
            set {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod()]
        public void CodeGeneratorTest() {
            var vehicles = new HashSet<Vehicle> { 
                new Car() { Speed = 160 }, new Car() { Speed = 120 }, new Car() { Speed = 230 },
                new Ship { Speed = 80 }, new Ship() { Speed = 60 }, new Ship() { Speed = 110 },
                new Plane { Speed = 420 }, new Plane() { Speed = 840 }, new Plane() { Speed = 720 }
            };

            Assert.AreEqual(vehicles.Average((Car c) => c.Speed),
                            vehicles.OfType<Car>().Average(c => c.Speed));

            Assert.AreEqual(vehicles.First((Car c) => c.Speed < 150),
                            vehicles.OfType<Car>().First(c => c.Speed < 150));

            Assert.AreEqual(vehicles.All((Ship s) => s.Speed < 100),
                            vehicles.OfType<Ship>().All(s => s.Speed < 100));

            Assert.IsTrue(Enumerable.SequenceEqual(
                            vehicles.Select((Ship s) => s.Speed),
                            vehicles.OfType<Ship>().Select(s => s.Speed)));

            Assert.IsTrue(Enumerable.SequenceEqual(
                            vehicles.SkipWhile((Plane p) => p.Speed < 500),
                            vehicles.OfType<Plane>().SkipWhile(p => p.Speed < 500)));

            Assert.IsTrue(Enumerable.SequenceEqual(
                            vehicles.OrderBy((Plane p) => p.Speed),
                            vehicles.OfType<Plane>().OrderBy(p => p.Speed)));
        }


        abstract class Vehicle {
            public double Speed;
        }

        class Car : Vehicle { }
        class Ship : Vehicle { }
        class Plane : Vehicle { }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Whaeth

Hungary Hungary
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 8 May 2012
Article Copyright 2011 by Whaeth
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid