public void ContextSetup()
            {
                var masterModel  = new MasterModel();
                var server1      = masterModel.CreateCruiseServer(x => x.Url = "http://www.example.com/1");
                var server2      = masterModel.CreateCruiseServer(x => x.Url = "http://www.example.com/2");
                var ccReaderData = new Projects {
                    Items = new[] { new ProjectsProject(), new ProjectsProject() }
                };
                var mappedData = new CcProjectCollectionViewModel
                {
                    Items = new[] { new CcProjectViewModel {
                                        Name = "Homer Wuz Here"
                                    } }
                };

                var ccReaderResponse =
                    NetworkResponse.Success(ccReaderData);

                var statusProvider = S <ISystemStatusProvider>();

                statusProvider.Stub(x => x.GetSystemStatus()).Return(masterModel);

                var ccReader = S <ICcReader>();

                ccReader.Stub(x => x.GetStatus("http://www.example.com/1")).Return(ccReaderResponse);

                var mapper = S <IMapper>();

                mapper.Stub(x => x.Map <Projects, CcProjectCollectionViewModel>(ccReaderData)).Return(mappedData);

                var provider = new CruiseProjectModelProvider(ccReader, mapper, statusProvider);

                _result = provider.GetProjects(server1.Id);
            }
            public void ContextSetup()
            {
                var masterModel = new MasterModel();

                _project1 = masterModel.CreateProject(); //1
                _project2 = masterModel.CreateProject(); //2

                var server1 = masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/1";
                    x.Name = "1";
                });
                var server2 = masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/2";
                    x.Name = "2";
                });

                var statusProvider = S <ISystemStatusProvider>();

                statusProvider.Stub(x => x.GetSystemStatus())
                .Return(masterModel);

                var cruiseProjectProvider = S <ICruiseProjectModelProvider>();
                var projectResponse1      = NetworkResponse.Success(new CcProjectCollectionViewModel
                {
                    Items = new[] { new CcProjectViewModel {
                                        Name = "1.1"
                                    }, new CcProjectViewModel {
                                        Name = "1.2"
                                    } }
                });
                var projectResponse2 = NetworkResponse.Success(new CcProjectCollectionViewModel
                {
                    Items = new[] { new CcProjectViewModel {
                                        Name = "2.1"
                                    }, new CcProjectViewModel {
                                        Name = "2.2"
                                    } }
                });

                cruiseProjectProvider.Stub(x => x.GetProjects(server1.Id)).Return(projectResponse1);
                cruiseProjectProvider.Stub(x => x.GetProjects(server2.Id)).Return(projectResponse2);

                var mapper = new StubMapper()
                             .StubResult(new[]
                {
                    new EditProjectCruiseServerViewModel {
                        Url = "Mapped 1", Id = server1.Id
                    },
                    new EditProjectCruiseServerViewModel {
                        Url = "Mapped 2", Id = server2.Id
                    }
                });
                var provider = new AdminViewModelProvider(statusProvider, mapper, cruiseProjectProvider);

                _result = provider.GetEditProjectViewModel(null);
            }
Beispiel #3
0
            public void Should_remove_cruise_server()
            {
                var model   = new MasterModel();
                var server1 = model.CreateCruiseServer(x => { x.Url = "http://www.example.com/1"; x.Name = "1"; });
                var server2 = model.CreateCruiseServer(x => { x.Url = "http://www.example.com/2"; x.Name = "2"; });
                var server3 = model.CreateCruiseServer(x => { x.Url = "http://www.example.com/3"; x.Name = "3"; });

                model.RemoveCruiseServer(server2.Id);

                model.CruiseServers.Length.ShouldEqual(2);
                model.CruiseServers.Count(x => x.Id.Equals(server1.Id)).ShouldEqual(1);
                model.CruiseServers.Count(x => x.Id.Equals(server3.Id)).ShouldEqual(1);
            }
            public void ContextSetup()
            {
                _masterModel = new MasterModel();
                var cruiseServer = _masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "https://example.com/server1";
                    x.Name = "Server 1";
                });

                _zBuildLightsProject = _masterModel.CreateProject();
                _zBuildLightsProject.CruiseProjectAssociations = new[]
                {
                    new CruiseProjectAssociation {
                        Name = "Project 1.1", ServerId = cruiseServer.Id
                    },
                    new CruiseProjectAssociation {
                        Name = "Project 1.2", ServerId = cruiseServer.Id
                    }
                };

                var cruiseReader = new StubCcReader()
                                   .WithResponse(cruiseServer.Url,
                                                 NetworkResponse.Fail <Projects>("Could not reach server or something bad happened."));

                var updater = new ProjectStatusUpdater(cruiseReader);

                updater.UpdateAllProjectStatuses(_masterModel);
            }
            public void ContextSetup()
            {
                var masterModel = new MasterModel();
                var server1     = masterModel.CreateCruiseServer(x => x.Url = "http://www.example.com/1");
                var server2     = masterModel.CreateCruiseServer(x => x.Url = "http://www.example.com/2");

                var ccReaderResponse = NetworkResponse.Fail <Projects>("Network request failed.", new Exception("I don't wanna"));

                var statusProvider = S <ISystemStatusProvider>();

                statusProvider.Stub(x => x.GetSystemStatus()).Return(masterModel);

                var ccReader = S <ICcReader>();

                ccReader.Stub(x => x.GetStatus("http://www.example.com/1")).Return(ccReaderResponse);

                IMapper doNotUseMapper = null;

                var provider = new CruiseProjectModelProvider(ccReader, doNotUseMapper, statusProvider);

                _result = provider.GetProjects(server1.Id);
            }
            public void ContextSetup()
            {
                var masterModel = new MasterModel();

                masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/1";
                    x.Name = "1";
                });
                masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/2";
                    x.Name = "2";
                });

                var mappedServers = new[]
                {
                    new EditCruiseServerViewModel {
                        Url = "url 1"
                    },
                    new EditCruiseServerViewModel {
                        Url = "url 2"
                    }
                };

                var statusProvider = S <ISystemStatusProvider>();

                statusProvider.Stub(x => x.GetSystemStatus())
                .Return(masterModel);

                var mapper = S <IMapper>();

                mapper.Stub(x => x.Map <CruiseServer[], EditCruiseServerViewModel[]>(masterModel.CruiseServers))
                .Return(mappedServers);
                var provider = new AdminViewModelProvider(statusProvider, mapper, null);

                _result = provider.GetCruiseServerViewModels();
            }
            public void ContextSetup()
            {
                _masterModel = new MasterModel();
                var cruiseServer = _masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "https://example.com/server1";
                    x.Name = "Server 1";
                });

                _zBuildLightsProject = _masterModel.CreateProject();
                _zBuildLightsProject.CruiseProjectAssociations = new[]
                {
                    new CruiseProjectAssociation {
                        Name = "Project 1.1", ServerId = cruiseServer.Id
                    },
                    new CruiseProjectAssociation {
                        Name = "Project 1.2", ServerId = cruiseServer.Id
                    },
                    new CruiseProjectAssociation {
                        Name = "Project 1.3", ServerId = cruiseServer.Id
                    }
                };

                var ccReaderDataServer1 = new Projects
                {
                    Items = new ProjectsProject[]
                    {
                        New.ProjectsProject.Name("Project 1.1")
                        .Activity(CcBuildActivity.Sleeping)
                        .Status(CcBuildStatus.Unknown),
                        New.ProjectsProject.Name("Project 1.2")
                        .Activity(CcBuildActivity.Sleeping)
                        .Status(CcBuildStatus.Success),
                        New.ProjectsProject.Name("Project 1.3")
                        .Activity(CcBuildActivity.Sleeping)
                        .Status(CcBuildStatus.Success),
                        New.ProjectsProject.Name("Detractor")
                        .Activity(CcBuildActivity.Sleeping)
                        .Status(CcBuildStatus.Success)
                    }
                };

                var cruiseReader = new StubCcReader()
                                   .WithResponse(cruiseServer.Url, NetworkResponse.Success(ccReaderDataServer1));

                var updater = new ProjectStatusUpdater(cruiseReader);

                updater.UpdateAllProjectStatuses(_masterModel);
            }
Beispiel #8
0
            public void ContextSetup()
            {
                var existingMasterModel = new MasterModel();

                existingMasterModel.CreateCruiseServer(x =>
                {
                    x.Name = "Existing";
                    x.Url  = "foo";
                });

                var repository = new StubMasterModelRepository();

                repository.UseCurrentModel(existingMasterModel);

                var creator = new CruiseServerManager(repository);

                _result = creator.Create("Existing", "http://example.com:8088/cc.xml");

                _savedModel = repository.LastSaved;
            }
Beispiel #9
0
        public MasterModel ToDomainObject()
        {
            var masterModel = new MasterModel
            {
                LastUpdatedDate = LastUpdatedDate,
            };

            foreach (var jsonProject in Projects)
            {
                masterModel.CreateProject(jsonProject.InitializeDomainObject());
            }
            foreach (var jsonCruiseServer in CruiseServers)
            {
                masterModel.CreateCruiseServer(jsonCruiseServer.InitializeDomainObject());
            }

            var unassignedLights = UnassignedLights ?? new JsonLight[0];

            masterModel.AddUnassignedLights(unassignedLights.Select(x => x.ToDomainObject()));
            return(masterModel);
        }
Beispiel #10
0
 public void ContextSetup()
 {
     _model = new MasterModel();
     _model.CreateCruiseServer(x => { x.Url = "http://www.example.com/1"; x.Name = "1"; });
     _model.CreateCruiseServer(x => { x.Url = "http://www.example.com/2"; x.Name = "2"; });
 }
            public void Should_serialize_and_deserialize()
            {
                AutoMapperConfig.Initialize();
                var container = IoC.Initialize();

                var masterModel = new MasterModel {
                    LastUpdatedDate = DateTime.Now
                };

                var server1 = masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/1";
                    x.Name = "One";
                });
                var server2 = masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/2";
                    x.Name = "Two";
                });

                var core = masterModel.CreateProject(x =>
                {
                    x.Name       = "Core";
                    x.StatusMode = StatusMode.Success;
                    x.CcXmlUrl   = "http://someserver:8888/cc.xml";
                    x.CruiseProjectAssociations = new[]
                    {
                        new CruiseProjectAssociation {
                            Name = "I like toast", ServerId = server1.Id
                        },
                        new CruiseProjectAssociation {
                            Name = "I like jam", ServerId = server2.Id
                        }
                    };
                });

                core.CreateGroup(x => x.Name = "SnP Square")
                .AddLight(new Light(new ZWaveValueIdentity(1, 1, 123))
                {
                    Color = LightColor.Green, SwitchState = SwitchState.On
                })
                .AddLight(new Light(new ZWaveValueIdentity(1, 2, 123))
                {
                    Color = LightColor.Yellow, SwitchState = SwitchState.Off
                })
                .AddLight(new Light(new ZWaveValueIdentity(1, 3, 123))
                {
                    Color = LightColor.Red, SwitchState = SwitchState.Off
                })
                ;
                core.CreateGroup(x => x.Name = "SnP Near Matt")
                .AddLight(new Light(new ZWaveValueIdentity(1, 4, 123))
                {
                    Color = LightColor.Green, SwitchState = SwitchState.On
                })
                .AddLight(new Light(new ZWaveValueIdentity(1, 5, 123))
                {
                    Color = LightColor.Yellow, SwitchState = SwitchState.Off
                })
                .AddLight(new Light(new ZWaveValueIdentity(1, 6, 123))
                {
                    Color = LightColor.Red, SwitchState = SwitchState.Off
                })
                ;

                var apps = masterModel.CreateProject(x =>
                {
                    x.StatusMode = StatusMode.BrokenAndBuilding;
                    x.Name       = "Apps";
                });

                apps.CreateGroup(x => x.Name = "Near Window")
                .AddLight(new Light(new ZWaveValueIdentity(1, 7, 123))
                {
                    Color = LightColor.Green, SwitchState = SwitchState.Off
                })
                .AddLight(new Light(new ZWaveValueIdentity(1, 8, 123))
                {
                    Color = LightColor.Yellow, SwitchState = SwitchState.On
                })
                .AddLight(new Light(new ZWaveValueIdentity(1, 9, 123))
                {
                    Color = LightColor.Red, SwitchState = SwitchState.On
                })
                ;

                masterModel.AddUnassignedLight(new Light(new ZWaveValueIdentity(3333, 3, 123)));

                //Act
                var serializer = container.GetInstance <IJsonSerializerService>();
                var json       = serializer.SerializeMasterModel(masterModel);

                Console.WriteLine(json);

                var deserialized = serializer.DeserializeMasterModel(json);

                var comparer =
                    new CompareLogic(new ComparisonConfig
                {
                    MembersToIgnore = new List <string> {
                        "SwitchState", "StatusMode"
                    }
                });
                var result = comparer.Compare(masterModel, deserialized);

                if (!result.AreEqual)
                {
                    Console.WriteLine("Comparison failed!:");
                    Console.WriteLine("\t{0}", result.DifferencesString);
                    result.AreEqual.ShouldBeTrue();
                }
            }
            public void ContextSetup()
            {
                _projectViewModel = new EditProjectViewModel {
                    Name = "I'm Mapped"
                };

                var masterModel            = new MasterModel();
                var project1               = masterModel.CreateProject(); //1
                var projectWeAreLookingFor = masterModel.CreateProject(); //2
                var project3               = masterModel.CreateProject(); //3

                var server1 = masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/1";
                    x.Name = "1";
                });
                var server2 = masterModel.CreateCruiseServer(x =>
                {
                    x.Url  = "http://www.example.com/2";
                    x.Name = "2";
                });

                var statusProvider = S <ISystemStatusProvider>();

                statusProvider.Stub(x => x.GetSystemStatus())
                .Return(masterModel);

                var cruiseProjectProvider = S <ICruiseProjectModelProvider>();
                var projectResponse1      = NetworkResponse.Success(new CcProjectCollectionViewModel
                {
                    Items = new[] { new CcProjectViewModel {
                                        Name = "1.1"
                                    }, new CcProjectViewModel {
                                        Name = "1.2"
                                    } }
                });
                var projectResponse2 = NetworkResponse.Success(new CcProjectCollectionViewModel
                {
                    Items = new[] { new CcProjectViewModel {
                                        Name = "2.1"
                                    }, new CcProjectViewModel {
                                        Name = "2.2"
                                    } }
                });

                cruiseProjectProvider.Stub(x => x.GetProjects(server1.Id)).Return(projectResponse1);
                cruiseProjectProvider.Stub(x => x.GetProjects(server2.Id)).Return(projectResponse2);


                var mapper = S <IMapper>();

                mapper.Stub(x => x.Map <Project, EditProjectViewModel>(projectWeAreLookingFor))
                .Return(_projectViewModel);
                mapper.Stub(x => x.Map <CruiseServer[], EditProjectCruiseServerViewModel[]>(masterModel.CruiseServers))
                .Return(new[]
                {
                    new EditProjectCruiseServerViewModel {
                        Url = "foo 1", Id = server1.Id
                    },
                    new EditProjectCruiseServerViewModel {
                        Url = "foo 2", Id = server2.Id
                    }
                });
                var provider = new AdminViewModelProvider(statusProvider, mapper, cruiseProjectProvider);

                _result = provider.GetEditProjectViewModel(projectWeAreLookingFor.Id);
            }