Esempio n. 1
0
 public void When_Raise_Append_Handle()
 {
     FakeContainer.Create().Add <IHandle <MessageTest> >(new Handle <MessageTest>());
     Message.Raise(new MessageTest("TEST_CASE", "TEST MESSAGE"));
     Assert.AreEqual("MessageTest", Locator.Service <IHandle <MessageTest> >().Key);
     Assert.True(Locator.Service <IHandle <MessageTest> >().Any());
 }
Esempio n. 2
0
        public FakeContainer CreateContainerWithConfig(string lang)
        {
            var fakeContainer = new FakeContainer();

            fakeContainer._instances.Add(typeof(IUserSetting), new FakeUserSetting(lang));
            return(fakeContainer);
        }
Esempio n. 3
0
        public void When_ResolvingQubits_UsingIsakovWrapper_TheCouplingsAndBiases_AreDumped_Before_ResolverIsInvoked()
        {
            var processService      = FakeContainer.GetProcessService();
            var fileService         = FakeContainer.GetFileService();
            var procWorkindDir      = "DIR";
            var procName            = "PROC";
            var args                = "ARGS";
            var scriptInputFileName = "latticeFile";

            processService.StartProcess(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>())
            .Returns(new StreamReader(Stream.Null));

            var input     = new decimal[] { 1, 2, 3, 4 };
            var couplings = new List <ICoupling <int, decimal> >();

            couplings.Add(new Coupling <int, decimal>(1, 2, 2));
            var biases = new List <IBias <int, decimal> >();

            biases.Add(new Bias <int, decimal>(1, 0));

            var resolver = new IsakovScriptQubitsResolver <decimal>(processService, procWorkindDir, procName, args, scriptInputFileName, fileService);

            resolver.Resolve(input, biases, couplings);

            Received.InOrder(() =>
            {
                fileService.WriteToFile(scriptInputFileName, Arg.Any <string>());
                processService.Received(1).StartProcess(procWorkindDir, procName, args);
            });
        }
        public void When_Requesting_SimpleAPI_ToResolve_AllAppropriateActors_AreInvoked()
        {
            var facade             = FakeContainer.GetFacade <int, int, int, int>();
            var converter          = FakeContainer.GetQubitsToGroupsConverter <int>();
            var resolver           = FakeContainer.GetResolvver <int, int, int, int>();
            var api                = new QubitsCalculationAPI <int, int, int, int>(facade, resolver, converter);
            var input              = new[] { 1, 2, 3, 4 };
            var couplingsAndBiases = new CouplingsAndBiases <int, int, int>();

            couplingsAndBiases.AddBias(0, 0);
            couplingsAndBiases.AddCoupling(0, 0, 0);
            facade.GetCouplingsAndBiases(input).Returns(couplingsAndBiases);
            var resolveResponse  = new List <IQubitsResolvingResponse>();
            var sortedQubitsList = new List <short>();

            resolveResponse.Add(new IsakovScriptResponse(1, sortedQubitsList, 1));
            resolver.Resolve(input, couplingsAndBiases.Biases, couplingsAndBiases.Couplings).Returns(resolveResponse);

            api.Resolve(input);

            Received.InOrder(() =>
            {
                facade.GetCouplingsAndBiases(input);
                resolver.Resolve(input, couplingsAndBiases.Biases, couplingsAndBiases.Couplings);
                converter.DivideInputIntoGroupsByQubits(input, Arg.Is <IEnumerable <IEnumerable <short> > >(arg =>
                                                                                                            arg.Count() == 1 && arg.First().Equals(sortedQubitsList)));
            });
        }
Esempio n. 5
0
        protected override void Initialize()
        {
            // initialize gametext
            ResetText();

            // initialize common structures
            var personal   = GetFilteredFolder(GameFile.PersonalStats, z => Path.GetFileNameWithoutExtension(z) == "personal_total");
            var learn      = this[GameFile.Learnsets][0];
            var splitLearn = learn.Split(0x104);

            Learn = new FakeContainer(splitLearn);
            Data  = new GameData
            {
                MoveData = new DataCache <Move>(this[GameFile.MoveStats]) // mini
                {
                    Create = z => new Move7(z),
                    Write  = z => z.Write(),
                },
                LevelUpData = new DataCache <Learnset>(Learn)
                {
                    Create = z => new Learnset8(z),
                    Write  = z => z.Write(),
                },

                // folders
                PersonalData  = new PersonalTable(personal[0], Game),
                EvolutionData = new DataCache <EvolutionSet>(GetFilteredFolder(GameFile.Evolutions))
                {
                    Create = data => new EvolutionSet8(data),
                    Write  = evo => evo.Write(),
                },
            };
        }
Esempio n. 6
0
        public void BasicFakeContainerTest()
        {
            FakeContainer container = new FakeContainer();

            ImportConstructorService importConstructorService =
                container.Locate<ImportConstructorService>();

            Assert.NotNull(importConstructorService);
            Assert.NotNull(importConstructorService.BasicService);
        }
Esempio n. 7
0
        public void When_Invalid_Model_No_Call_Repository()
        {
            FakeContainer.Create().Add <IHandle <ValidationError> >(new Handle <ValidationError>());
            var customer = new Customer {
                Name = "AG", BirthDate = DateTime.Today.AddYears(-3)
            };

            _service.Insert(customer);
            _repo.Verify(r => r.Insert(customer), Times.Never);
        }
Esempio n. 8
0
        public void Owned_container_should_be_disposed()
        {
            var fakeContainer = new FakeContainer();

            var container = new UnityObjectBuilder(fakeContainer, true);

            container.Dispose();

            Assert.True(fakeContainer.Disposed);
        }
Esempio n. 9
0
        public void Externally_owned_container_should_not_be_disposed()
        {
            var fakeContainer = new FakeContainer();

            var container = new UnityObjectBuilder(fakeContainer, false);

            container.Dispose();

            Assert.False(fakeContainer.Disposed);
        }
Esempio n. 10
0
        public void When_Invalid_Raise_Messages()
        {
            var validator = new CustomerValidator();
            var customer  = new Customer();

            FakeContainer.Create().Add <IHandle <ValidationError> >(new ValidationErrorHandle());

            Assert.False(validator.Validate(customer));
            var handle = Locator.Service <IHandle <ValidationError> >();

            Assert.True(handle.Any());
        }
Esempio n. 11
0
        public void ACallTo()
        {
            FakeContainer container = new FakeContainer();

            A.CallTo(() => container.Locate<IBasicService>(null, null, null).TestMethod()).Returns(5);

            ImportConstructorService importConstructorService =
                container.Locate<ImportConstructorService>();

            Assert.Equal(5, importConstructorService.TestMethod());

            A.CallTo(() => container.Locate<IBasicService>(null, null, null).TestMethod()).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 12
0
        public void ConfigureArrangeTest()
        {
            FakeContainer container = new FakeContainer();

            container.Configure(c => c.Fake<IBasicService>().
                Arrange(x => A.CallTo(() => x.TestMethod()).Returns(5)).
                AndSingleton());

            ImportConstructorService importConstructorService =
                container.Locate<ImportConstructorService>();

            Assert.Equal(5, importConstructorService.TestMethod());

            A.CallTo(() => container.Locate<IBasicService>(null, null, null).TestMethod()).MustHaveHappened(Repeated.Exactly.Once);
        }
Esempio n. 13
0
        public void When_Requesting_DataExtraction_BothCouplesAndBiases_Are_Extracted()
        {
            var couplingProvider = FakeContainer.GetCouplingProvider <int, int>();
            var biasProvider     = FakeContainer.GetBiasProvider <int, int>();
            var facade           = new QuantumDataExtractionFacade <int, int, int>(couplingProvider, biasProvider);
            var input            = new int[] { 1, 2 };

            var result = facade.GetCouplingsAndBiases(input);

            Received.InOrder(() =>
            {
                biasProvider.GetBias(1);
                couplingProvider.GetCoupling(1, 2);
                biasProvider.GetBias(2);
            });
        }
Esempio n. 14
0
        /// <summary>
        /// Test resolve.
        /// </summary>
        public void TestResolve()
        {
            Bmw bmw = new Bmw();

            FakeContainer fakeContainer = new FakeContainer(resolveFunc: (resolution) =>
            {
                Assert.AreEqual(typeof(Bmw), resolution.InterfaceType);

                return(bmw);
            });

            var service = fakeContainer.Resolve <ICar>();

            Assert.IsNotNull(service);
            Assert.AreEqual(typeof(Bmw), service.GetType());
        }
Esempio n. 15
0
        public override void Initialize()
        {
            base.Initialize();

            // initialize gametext
            ResetText();

            // initialize common structures
            var personal   = GetFilteredFolder(GameFile.PersonalStats, z => Path.GetFileNameWithoutExtension(z) == "personal_total");
            var learn      = this[GameFile.Learnsets][0];
            var splitLearn = learn.Split(0x104);

            Learn = new FakeContainer(splitLearn);

            var move = this[GameFile.MoveStats];

            ((FolderContainer)move).Initialize();
            Data = new GameData
            {
                MoveData = new DataCache <IMove>(move)
                {
                    Create = FlatBufferConverter.DeserializeFrom <Waza8>,
                    Write  = z => FlatBufferConverter.SerializeFrom((Waza8)z),
                },
                LevelUpData = new DataCache <Learnset>(Learn)
                {
                    Create = z => new Learnset8(z),
                    Write  = z => z.Write(),
                },

                // folders
                PersonalData  = new PersonalTable(personal[0], Game),
                EvolutionData = new DataCache <EvolutionSet>(GetFilteredFolder(GameFile.Evolutions))
                {
                    Create = data => new EvolutionSet8(data),
                    Write  = evo => evo.Write(),
                },
            };
        }
Esempio n. 16
0
        protected override void Initialize()
        {
            // initialize gametext
            ResetText();

            // initialize common structures
            var personal   = GetFilteredFolder(GameFile.PersonalStats, z => Path.GetFileNameWithoutExtension(z) == "personal_total");
            var learn      = this[GameFile.Learnsets][0];
            var splitLearn = learn.Split(0x104);

            Learn = new FakeContainer(splitLearn);

            var move = this[GameFile.MoveStats];

            ((FolderContainer)move).Initialize();
            Data = new GameData
            {
                MoveData = new DataCache <Move>(move)
                {
                    Create = Waza8Reader.ReadPlaceholder,
                    Write  = _ => throw new ArgumentException(),
                },
        public void ServicesDependencies()
        {
            var fakeContainer = new FakeContainer();

            IO.Container = fakeContainer;

            Initialize.Reboot();

            var dependencies = fakeContainer.TypeMap.Values.ToDictionary(type => type, type => type.GetConstructors().First().GetParameters().Select(p => p.ParameterType).ToList());

            foreach (var dependency in dependencies.OrderBy(k => k.Value.Count))
            {
                if (dependency.Value.Any())
                {
                    Console.WriteLine("" + dependency.Key.Name + " directly depends on " + string.Join(", ", dependency.Value.Select(p => p.Name)));
                }
                else
                {
                    Console.WriteLine(dependency.Key.Name + " has no dependencies");
                }
            }
            IO.Container = new IoCContainer();
        }
Esempio n. 18
0
        public void ConfigureAssertTest()
        {
            FakeContainer container = new FakeContainer();

            container.Configure(c => c.Fake<IBasicService>().
                Arrange(x => A.CallTo(() => x.TestMethod()).Returns(5)).
                Assert(x => A.CallTo(() => x.TestMethod()).MustHaveHappened(Repeated.Exactly.Twice)));

            ImportConstructorService importConstructorService =
                container.Locate<ImportConstructorService>();

            Assert.Equal(5, importConstructorService.TestMethod());

            try
            {
                container.Assert();

                throw new Exception("This should have thrown an exception from the assert");
            }
            catch (ExpectationException)
            {
                // we are expecting this
            }
        }
Esempio n. 19
0
        private FakeMonitor GetMonitor()
        {
            var container = new FakeContainer();

            return(new FakeMonitor(container));
        }