コード例 #1
0
 protected override void Load(ContainerBuilder builder)
 {
     RegistrationExtensions.Register(builder, c => new CustomWebDownloader()).As <IWebDownloader>().ExternallyOwned();
     RegistrationExtensions.Register(builder, c => new HashtagIndependentInMemoryCrawlerHistoryService()).As <ICrawlerHistory>().InstancePerDependency();
     RegistrationExtensions.Register(builder, c => new InMemoryCrawlerQueueService()).As <ICrawlerQueue>().InstancePerDependency();
     RegistrationExtensions.Register(builder, c => new LogLoggerBridge(CreateLogger())).As <ILog>().InstancePerDependency();
     RegistrationExtensions.Register(builder, c => new NativeTaskRunnerService()).As <ITaskRunner>().InstancePerDependency();
     RegistrationExtensions.Register(builder, (c, p) => new RobotService(ParameterExtensions.TypedAs <IEnumerable <Uri> >(p), ResolutionExtensions.Resolve <IWebDownloader>(c))).As <IRobot>().InstancePerDependency();
     RegistrationExtensions.Register(builder, (c, p) => new CrawlerRulesService(ParameterExtensions.TypedAs <Crawler>(p), ResolutionExtensions.Resolve <IRobot>(c, p), ParameterExtensions.TypedAs <IEnumerable <Uri> >(p))).As <ICrawlerRules>().InstancePerDependency();
 }
        public void That_returns_false_if_expectation_is_not_met(Parameter <string> parameter, IConstraint constraint)
        {
            Mock.Get(constraint).Setup(p => p.ApplyTo(It.IsAny <string>())).Returns((string value) => new ConstraintResult(constraint, value, false));

            var mock = new Mock <ISynchronousService>();

            mock.Setup(p => p.Echo(It.IsAny <string>())).Returns("world");

            var service = mock.Object;

            var actual = service.Echo("hello world");

            Assert.That(() => mock.Verify(p => p.Echo(ParameterExtensions.That(parameter, constraint))), Throws.InstanceOf <MockException>());
        }
        public void That_returns_true_if_expectation_is_not_met_by_async_selected_value(Parameter <CompositeParameter> parameter, IConstraint constraint, CompositeParameter testParameter)
        {
            Mock.Get(constraint).Setup(p => p.ApplyTo(It.IsAny <string>())).Returns((string value) => new ConstraintResult(constraint, value, false));

            var mock = new Mock <IServiceWithCompositeParameter>();

            mock.Setup(p => p.DoSomething(It.IsAny <CompositeParameter>()));

            var service = mock.Object;

            service.DoSomething(testParameter);

            Assert.That(() => mock.Verify(p => p.DoSomething(ParameterExtensions.That(parameter, p => p.GetString(), constraint))), Throws.InstanceOf <MockException>());

            Mock.Get(constraint).Verify(p => p.ApplyTo(testParameter.StringProperty));
        }
        public void Assert_returns_true_if_expectation_is_met(Parameter <string> parameter, IConstraint constraint)
        {
            Mock.Get(constraint).Setup(p => p.ApplyTo(It.IsAny <string>())).Returns((string value) => new ConstraintResult(constraint, value, true));

            Mock.Get(constraint).Setup(p => p.Resolve()).Returns(constraint);

            var mock = new Mock <ISynchronousService>();

            mock.Setup(p => p.Echo(It.IsAny <string>())).Returns("world");

            var service = mock.Object;

            var actual = service.Echo("hello world");

            mock.Verify(p => p.Echo(ParameterExtensions.Assert(parameter, constraint)));
        }
        public void Assert_returns_true_if_expectation_is_met_by_selected_value(Parameter <CompositeParameter> parameter, IConstraint constraint, CompositeParameter testParameter)
        {
            Mock.Get(constraint).Setup(p => p.ApplyTo(It.IsAny <string>())).Returns((string value) => new ConstraintResult(constraint, value, true));

            Mock.Get(constraint).Setup(p => p.Resolve()).Returns(constraint);

            var mock = new Mock <IServiceWithCompositeParameter>();

            mock.Setup(p => p.DoSomething(It.IsAny <CompositeParameter>()));

            var service = mock.Object;

            service.DoSomething(testParameter);

            mock.Verify(p => p.DoSomething(ParameterExtensions.Assert(parameter, p => p.StringProperty, constraint)));

            Mock.Get(constraint).Verify(p => p.ApplyTo(testParameter.StringProperty));
        }
コード例 #6
0
ファイル: Mesh.cs プロジェクト: X-Hax/SA3D
        public static Mesh Read(byte[] source, uint address, uint imageBase, ref IndexAttributes indexAttribs)
        {
            // getting the addresses and sizes
            uint parameters_addr  = source.ToUInt32(address) - imageBase;
            int  parameters_count = source.ToInt32(address + 4);

            uint primitives_addr = source.ToUInt32(address + 8) - imageBase;
            int  primitives_size = source.ToInt32(address + 12);

            // reading the parameters
            List <IParameter> parameters = new();

            for (int i = 0; i < parameters_count; i++)
            {
                parameters.Add(ParameterExtensions.Read(source, parameters_addr));
                parameters_addr += 8;
            }

            // getting the index attribute parameter
            var p = parameters.FirstOrDefault(x => x.Type == ParameterType.IndexAttributes);

            if (p != null)
            {
                indexAttribs = ((IndexAttributeParameter)p).IndexAttributes;
            }

            // reading the primitives
            List <Poly> primitives = new();
            uint        end_pos    = (uint)(primitives_addr + primitives_size);

            while (primitives_addr < end_pos)
            {
                // if the primitive isnt valid
                if (source[primitives_addr] == 0)
                {
                    break;
                }
                primitives.Add(Poly.Read(source, ref primitives_addr, indexAttribs));
            }

            return(new Mesh(parameters.ToArray(), primitives.ToArray()));
        }
コード例 #7
0
 public void Should_throw_argument_null_exception_when_value_is_null()
 {
     Assert.Throws <ArgumentNullException>(() => ParameterExtensions.ThrowIfNull(null, "paramName"));
 }
コード例 #8
0
 public void Should_throw_argument_null_exception_when_string_value_is_empty()
 {
     Assert.Throws <ArgumentNullException>(() => ParameterExtensions.ThrowIfNullOrEmpty(string.Empty, "paramName"));
 }