Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainForm"/> class.
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            stopwatch = new Stopwatch();

            var assemblies           = new[] { Assembly.Load("CodeSharper.Core"), Assembly.Load("CodeSharper.Languages"), Assembly.Load("CodeSharper.Languages.CSharp"), Assembly.GetExecutingAssembly() };
            var runnableTypeResolver = new AutoRunnableResolver();
            var valueConverter       = new IntegerValueConverter();
            var interactiveService   = new ReplaceTextInteractiveService(this);

            var serviceFactory = new SimpleServiceFactory();

            serviceFactory.RegisterInteractiveService(interactiveService);

            var runnableFactory          = new DefaultRunnableFactory(runnableTypeResolver.ResolveRunnableTypes(assemblies), valueConverter, serviceFactory: serviceFactory);
            var fileDescriptorRepository = new FileDescriptorRepository("descriptors.json", assemblies);
            var autoDescriptorRepository = new AutoCommandDescriptorRepository(assemblies.SelectMany(assembly => assembly.GetTypes()));
            var descriptorRepository     = new MultiDescriptorRepository(
                Array <IDescriptorRepository>(fileDescriptorRepository, autoDescriptorRepository)
                );

            Bootstrapper   = new Bootstrapper(runnableFactory, descriptorRepository);
            compilerModule = new TextCompilerModule(Bootstrapper);
        }
Exemplo n.º 2
0
        public static void Constructor_ExpectedValues()
        {
            // Call
            var converter = new IntegerValueConverter();

            // Assert
            Assert.That(converter, Is.InstanceOf <IValueConverter>());
        }
Exemplo n.º 3
0
        public void ConvertBack_WithIntegerValueType_ReturnsExpectedResult(string value, int expectedResult)
        {
            // Setup
            var converter = new IntegerValueConverter();

            // Call
            object result = converter.ConvertBack(value, typeof(int), null, null);

            // Assert
            Assert.That(result, Is.EqualTo(expectedResult));
        }
Exemplo n.º 4
0
        public void Convert_WithValidValue_ReturnsExpectedString(int?value, string expectedValue)
        {
            // Setup
            var converter = new IntegerValueConverter();

            // Call
            object result = converter.Convert(value, typeof(string), null, null);

            // Assert
            Assert.That(result, Is.EqualTo(expectedValue));
        }
Exemplo n.º 5
0
        public void ConvertBack_WithNonIntegerValueType_ReturnsNull(object value)
        {
            // Setup
            var converter = new IntegerValueConverter();

            // Call
            object result = converter.ConvertBack(value, typeof(int), null, null);

            // Assert
            Assert.That(result, Is.Null);
        }
Exemplo n.º 6
0
        public void Convert_WithUnsupportedValue_ThrowsNotSupportedException(object unsupportedValue)
        {
            // Setup
            var converter = new IntegerValueConverter();

            // Call
            TestDelegate call = () => converter.Convert(unsupportedValue, typeof(string), null, null);

            // Assert
            string expectedMessage = $"Conversion from {unsupportedValue?.GetType().Name} is not supported.";

            Assert.That(call, Throws.Exception.InstanceOf <NotSupportedException>()
                        .And.Message.EqualTo(expectedMessage));
        }
Exemplo n.º 7
0
        public void ConvertBack_WithUnsupportedType_ThrowsNotSupportedException()
        {
            // Setup
            var converter = new IntegerValueConverter();

            Type unsupportedType = typeof(object);

            // Call
            TestDelegate call = () => converter.ConvertBack("1", unsupportedType, null, null);

            // Assert
            string expectedMessage = $"Conversion to {unsupportedType.Name} is not supported.";

            Assert.That(call, Throws.Exception.InstanceOf <NotSupportedException>()
                        .And.Message.EqualTo(expectedMessage));
        }