public void WhenBuilderIsFound__BuildMethodShouldBeInvoked()
        {
            var surfaceBuilderMock = new Mock <IPlateauBuilder>();
            var sut = new SurfaceBuilderFactory(new List <ISurfaceBuilder> {
                surfaceBuilderMock.Object
            });

            ISurfaceBuilder surfaceBuilder = sut.Generate(typeof(Plateau));

            Assert.NotNull(surfaceBuilder);
            Assert.True(surfaceBuilder is IPlateauBuilder);
        }
示例#2
0
        public ISurfaceBuilder Generate(Type surfaceTypes)
        {
            ISurfaceBuilder surfaceBuilder = null;

            if (surfaceTypes == typeof(Plateau))
            {
                surfaceBuilder = _surfaceBuilders.FirstOrDefault(builder => builder is IPlateauBuilder);
            }

            if (surfaceBuilder == null)
            {
                throw new DevelopmentException($"There is not defined surface builder for [{surfaceTypes}]");
            }

            return(surfaceBuilder);
        }
示例#3
0
        private static void Main()
        {
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;

            IServiceCollection serviceCollection = new ServiceCollection();

            serviceCollection.AddSingleton <IFileProcessor, BasicFileProcessor>();
            serviceCollection.AddTransient <IStreamReader, BasicStreamReader>();
            serviceCollection.AddSingleton <IVehicleFactory, VehicleFactory>();
            serviceCollection.AddImplementedTypes <IVehicleBuilder>(ServiceLifetime.Singleton, typeof(IVehicleBuilder).Assembly);
            serviceCollection.AddSingleton <IVehicleContextFactory, VehicleContextFactory>();
            serviceCollection.AddSingleton <ISurfaceBuilderFactory, SurfaceBuilderFactory>();
            serviceCollection.AddImplementedTypes <ISurfaceBuilder>(ServiceLifetime.Singleton, typeof(ISurfaceBuilder).Assembly);
            serviceCollection.AddTransient <IInputProviderFactory, InputProviderFactory>();
            serviceCollection.AddImplementedTypes <IInputProvider>(ServiceLifetime.Transient, typeof(IInputProvider).Assembly);
            serviceCollection.AddSingleton <IVehicleActionProvider, BulkStringVehicleActionProvider>();

            using (ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider())
            {
                InputProviderTypes inputProviderType = SelectInputProviderType();

                var            inputProviderFactory = serviceProvider.GetRequiredService <IInputProviderFactory>();
                IInputProvider inputProvider        = inputProviderFactory.Generate(inputProviderType);

                var surfaceBuilderFactory = serviceProvider.GetRequiredService <ISurfaceBuilderFactory>();

                var vehicleFactory = serviceProvider.GetRequiredService <IVehicleFactory>();

                var vehicleContextFactory = serviceProvider.GetRequiredService <IVehicleContextFactory>();

                var vehicleActionProvider = serviceProvider.GetRequiredService <IVehicleActionProvider>();

                string inputProviderArgument = GetInputProviderArgument(inputProvider);
                Input  input = inputProvider.Provide(inputProviderArgument);

                ISurfaceBuilder surfaceBuilder = surfaceBuilderFactory.Generate(typeof(Plateau));
                Surface         surface        = surfaceBuilder.Build(input.SurfaceParameter);

                foreach ((string vehicleParameter, string moveCommandParameter) in input.VehicleAndCommandsParameterList)
                {
                    IVehicleContext vehicleContext;
                    Vehicle         movable = vehicleFactory.Generate(VehicleTypes.Rover, vehicleParameter);
                    try
                    {
                        vehicleContext = vehicleContextFactory.Generate(surface, movable);
                    }
                    catch (VehicleDeployException)
                    {
                        Console.WriteLine($"Rover could not land on surface");
                        continue;
                    }

                    IEnumerable <VehicleActions> vehicleActions = vehicleActionProvider.Provide(moveCommandParameter);

                    try
                    {
                        foreach (VehicleActions action in vehicleActions)
                        {
                            vehicleContext.Move(action);
                        }

                        Console.WriteLine(vehicleContext.Vehicle.ToString());
                    }
                    catch (VehicleConnectionLostException)
                    {
                        Console.WriteLine($"Connection lost. Rover is not on surface anymore");
                    }
                }

                Exit(0);
            }
        }
示例#4
0
 public Context(ISurfaceBuilder surfaceBuilder, IRobotBuilder robotBuilder)
 {
     SurfaceBuilder = surfaceBuilder;
     RobotBuilder   = robotBuilder;
 }