public void ContextSetup()
            {
                var masterModel = new MasterModel();

                masterModel.CreateProject(); //1
                masterModel.CreateProject(); //2
                masterModel.CreateProject(); //3
                masterModel.CreateProject(); //4
                masterModel.CreateProject(); //5

                masterModel.AddUnassignedLight(new Light(new ZWaveValueIdentity(1, 22, 123)));

                var statusProvider = S <ISystemStatusProvider>();

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

                var mapper = S <IMapper>();

                mapper.Stub(x => x.Map <Project[], AdminProjectViewModel[]>(masterModel.Projects))
                .Return(new AdminProjectViewModel[3]);
                mapper.Stub(x => x.Map <Light[], AdminLightViewModel[]>(masterModel.UnassignedLights))
                .IgnoreArguments()
                .Return(new[] { new AdminLightViewModel {
                                    ZWaveIdentity = new ZWaveValueIdentity(1, 22, 444)
                                } });

                var provider = new AdminViewModelProvider(statusProvider, mapper, null);

                _result = provider.GetIndexViewModel();
            }
예제 #2
0
            public void ContextSetup()
            {
                var zWaveIdentity = new ZWaveValueIdentity(11, 23, 222);

                _light            = new Light(zWaveIdentity);
                _model            = new MasterModel();
                _destinationGroup = _model.CreateProject().CreateGroup();

                _model.AddUnassignedLight(_light);

                _model.AssignLightToGroup(zWaveIdentity, _destinationGroup.Id);
            }
예제 #3
0
            public void ContextSetup()
            {
                _masterModel = new MasterModel();
                var group = _masterModel.CreateProject().CreateGroup();

                group.AddLight(new Light(new ZWaveValueIdentity(1, 11, 1)));
                group.AddLight(new Light(new ZWaveValueIdentity(1, 22, 4)));
                group.AddLight(new Light(new ZWaveValueIdentity(1, 33, 5)));

                _masterModel.AddUnassignedLight(new Light(new ZWaveValueIdentity(1, 44, 123))
                {
                    Color = LightColor.Red
                });

                var allSwitches = new[]
                {
                    new ZWaveSwitch(new ZWaveValueIdentity(1, 11, 1)), //In a group
                    new ZWaveSwitch(new ZWaveValueIdentity(1, 15, 2)), //New
                    new ZWaveSwitch(new ZWaveValueIdentity(1, 16, 3)), //New
                    new ZWaveSwitch(new ZWaveValueIdentity(1, 22, 4)), //In a group
                    new ZWaveSwitch(new ZWaveValueIdentity(1, 22, 5)), //New (different value ID)
                    new ZWaveSwitch(new ZWaveValueIdentity(1, 33, 5)), //In a group
                    new ZWaveSwitch(new ZWaveValueIdentity(2, 11, 6)), //New (different home ID)
                    new ZWaveSwitch(new ZWaveValueIdentity(2, 22, 7))  //New (different home ID)
                };

                var network = S <IZWaveNetwork>();

                network.Stub(x => x.GetAllSwitches()).Return(allSwitches);

                var repository = S <IMasterModelRepository>();

                repository.Stub(x => x.GetCurrent()).Return(_masterModel);

                var service = new UnassignedLightService(network);

                service.SetUnassignedLights(_masterModel);
            }
            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();
                }
            }