public ContainerAdapter BuildNewAdapter(Container container)
        {
            container.Options.DefaultScopedLifestyle = new LifetimeScopeLifestyle();

            var currentAssembly = new[] {typeof(Helpers.CompositionRoot).Assembly};

            var concreteTypes = currentAssembly
                .GetImplementations(
                    ImplementationConvention.NameEndsWith,
                    new[] {"Repository"}
                ).ToList();

            var containerAdapter = new ContainerAdapter(container);

            containerAdapter.RegisterAbstractor(
                settings =>
                {
                    settings.ApplicationAssemblies = currentAssembly;
                    settings.ApplicationTypes = concreteTypes;
                });

            container.Register<ILogger, FakeLogger>(Lifestyle.Singleton);

            return containerAdapter;
        }
        public static void UpdateTag(XElement image)
        {
            image.Name = "img";

            var imgSrc = image.Attribute("base");
            if (!imgSrc.Value.StartsWith(Settings.ImageBase))
            {
                imgSrc.Value = Settings.ImageBase + "/" + imgSrc.Value;
            }

            var img = Path.GetFileNameWithoutExtension(imgSrc.Value).Split('-')[0];

            if (image.Attribute("src") == null)
                image.Add(new XAttribute("src", Settings.ImageBase + "/" + img + "-1280.jpg"));

            if (image.Attribute("srcset") == null)
            {
                var widths = new[] { 240, 320, 480, 640, 800, 960, 1280, 1600, 1920, 2400 };
                var srcset = string.Join(", ",
                    widths.Select(s => Settings.ImageBase + "/" + img + "-" + (s < 1000 ? "0" : "") + s + ".jpg " + s + "w"));

                image.Add(new XAttribute("srcset", srcset));
            }

            if (image.Attribute("sizes") == null)
            {
                const string sizes = "(max-width: 767px) 100vw, (max-width: 991px) 720px, (max-width: 1199px) 940px, 1140px";
                image.Add(new XAttribute("sizes", sizes));
            }
        }
示例#3
0
 public void Max2D()
 {
     var array1 = new double[,] { { 4, 2 } };
     Assert.AreEqual(4, array1.Max2D(), "Max2D()");
     var array2 = new[,] { { 4, double.NaN } };
     Assert.AreEqual(4, array2.Max2D(), "Max2D() with NaN");
     var array3 = new[] { 4, double.NaN };
     Assert.AreEqual(4, array3.Max(), "LINQ Max()");
 }
示例#4
0
 public void Min2D()
 {
     var array1 = new double[,] { { 4, 2 } };
     Assert.AreEqual(2, array1.Min2D(), "Min2D()");
     var array2 = new[,] { { 4, double.NaN } };
     Assert.AreEqual(double.NaN, array2.Min2D(), "Min2D() with NaN");
     Assert.AreEqual(4, array2.Min2D(true), "Min2D(true) with NaN");
     var array3 = new[] { 4, double.NaN };
     Assert.AreEqual(double.NaN, array3.Min(), "LINQ Min()");
 }
 private static void SendPasteCombination()
 {
     var inputs = new[]
     {
         GenerateKeystoke(VirtualKeyShort.LCONTROL),
         GenerateKeystoke(VirtualKeyShort.KEY_V),
         GenerateKeystoke(VirtualKeyShort.KEY_V, KEYEVENTF.KEYUP),
         GenerateKeystoke(VirtualKeyShort.LCONTROL, KEYEVENTF.KEYUP)
     };
     SendInput((uint) inputs.Length, inputs, INPUT.Size);
 }
示例#6
0
        public void should_format_non_collection_object_vertically()
        {
            var obj = new {Name = "The name", BirthYear = 2000};
            var writer = new StringWriter();
            obj.Format(writer);

            string formattedResult = writer.ToString();

            Assert.Equal(
                "Name:      The name\r\nBirthYear: 2000\r\n",
                formattedResult);
        }
        public void WebSourceCallbackHandlerNavigateToWithInvalidSchemesExpectedDoesNotInvokeStartUriProcess()
        {
            var schemes = new[] { "gopher", "mailto", "file", "ldap", "mailto", "net.pipe", "net.tcp", "news", "nntp", "telnet", "ldap", "uuid" };

            var env = new Mock<IEnvironmentRepository>();
            var handler = new WebSourceCallbackHandlerMock(env.Object);
            #pragma warning disable 168
            foreach(var scheme in schemes)
            #pragma warning restore 168
            {
                Assert.AreEqual(0, handler.StartUriProcessHitCount);
            }
        }
示例#8
0
        public sealed override async Task DisposeAsync(CancellationToken cancellationToken)
        {
            if (!this.IsDisposed)
            {
                var invertedCrc = (ushort)(~this.crc & ushort.MaxValue);
                var crcBytes =
                    new[] { (byte)(invertedCrc & byte.MaxValue), (byte)((invertedCrc >> 8) & byte.MaxValue) };
                await this.WriteAsync(crcBytes, 0, crcBytes.Length, cancellationToken);

                var writeBuffer = this.WriteBuffer;
                await writeBuffer.ReserveAsync(1, cancellationToken);
                writeBuffer[writeBuffer.Count++] = Frame.EndOfFrame;
                await base.DisposeAsync(cancellationToken);
            }
        }
        public void Get_Ignores_Unknown_Options()
        {
            const string name = "Testing";
            var commandLine = new [] { "--Banana=Blah" };

            var propertyMock = new Mock<PropertyInfo>();
            propertyMock.Setup(x => x.GetCustomAttributes(true)).Returns(new object[] { });

            var source = new DashedCommandLineSource(commandLine);

            string value;
            var result = source.Get(name, propertyMock.Object, out value);

            Assert.IsNull(value);
            Assert.IsFalse(result);
        }
        public void Get_Is_Not_Case_Sensitive()
        {
            const string name = "Testing";
            const string expected = "Blah";
            var commandLine = new [] { "--tEstinG=Blah" };

            var propertyMock = new Mock<PropertyInfo>();
            propertyMock.Setup(x => x.GetCustomAttributes(true)).Returns(new object[] { });

            var source = new DashedCommandLineSource(commandLine);

            string value;
            var result = source.Get(name, propertyMock.Object, out value);

            Assert.AreEqual(expected, value);
            Assert.IsTrue(result);
        }
        public void LogCostPerLine_CallsLogger_WhenCalled([NotNull, Frozen] ISelkieLogger logger,
                                                          [NotNull] AcoProxyLogger sut)
        {
            // Arrange
            var costPerLine = new[]
                              {
                                  1,
                                  2,
                                  3
                              };

            // Act
            sut.LogCostPerLine(costPerLine);

            // Assert
            logger.Received().Info(Arg.Is <string>(x => x == "CostPerLine: 1,2,3"));
        }
示例#12
0
        public void WriteCharacterArray()
        {
            var value = new[] { 'a', 'b', 'c' };

            bool eventWasRaised = false;
            using (var pipe = new ScriptOutputPipe())
            {
                pipe.OnScriptOutput +=
                    (s, e) =>
                    {
                        eventWasRaised = true;
                        Assert.AreEqual("abc", e.Text);
                    };
                pipe.Write(value);
            }

            Assert.IsTrue(eventWasRaised);
        }
        public void Get_Assumes_True_For_Booean_With_No_Value()
        {
            const string name = "Testing";
            const string expected = "True";
            var commandLine = new [] { "--Testing" };

            var propertyMock = new Mock<PropertyInfo>();
            propertyMock.SetupGet(x => x.PropertyType).Returns(typeof(bool));

            var source = new DashedCommandLineSource(commandLine);

            string value;
            var result = source.Get(name, propertyMock.Object, out value);

            propertyMock.VerifyGet(x => x.PropertyType);
            Assert.AreEqual(expected, value);
            Assert.IsTrue(result);
        }
示例#14
0
        public void should_format_collection_object_horizontally()
        {
            var collection = new[]
            {
                new SampleModel("Short Name", 2000, "United Kindom"),
                new SampleModel("A Longer Name", 2001, "China")
            };

            const string expected =
            @"Name           BirthYear  Country
            =========================================
            Short Name     2000       United Kindom
            A Longer Name  2001       China
            ";
            var writer = new StringWriter();
            collection.Format(writer);

            Assert.Equal(expected, writer.ToString());
        }
        public static Container GetContainer()
        {
            // Double-checked locking pattern

            // ReSharper disable once InvertIf
            if (_container == null)
            {
                lock (Lock)
                {
                    if (_container != null) return _container;

                    _container = new Container();

                    _container.Options.DefaultScopedLifestyle = new LifetimeScopeLifestyle();

                    var currentAssembly = new[] {typeof (CompositionRoot).Assembly};

                    var concreteTypes = currentAssembly
                        .GetImplementations(
                            ImplementationConvention.NameEndsWith,
                            new[] {"Repository"}
                        ).ToList();

                    var containerAdapter = new ContainerAdapter(_container);

                    containerAdapter.RegisterAbstractor(
                        cs =>
                        {
                            cs.ApplicationAssemblies = currentAssembly;
                            cs.ApplicationTypes = concreteTypes;
                        });

                    containerAdapter.RegisterSingleton<IUnitOfWork, FakeUnitOfWork>();
                    containerAdapter.RegisterSingleton<IStopwatch, FakeStopwatch>();
                    containerAdapter.RegisterScoped<ILogger, FakeLogger>();

                    _container.Verify();
                }
            }

            return _container;
        }
示例#16
0
        public void XmlCoercer_Coerce_Works_With_Array_Of_Int()
        {
            const string input = @"
            <ArrayOfint xmlns=""http://schemas.microsoft.com/2003/10/Serialization/Arrays"" xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"">
            <int>1</int>
            <int>4</int>
            <int>78</int>
            <int>222</int>
            </ArrayOfint>
            ";

            var expected = new [] { 1, 4, 78, 222 };

            var coercer = new XmlCoercerAttribute();

            int[] result;
            var coerced = coercer.Coerce(input, null, null, out result);

            CollectionAssert.AreEqual(expected, result);
            Assert.IsTrue(coerced);
        }
        public void ReleaseConvertersClearsNodesTest()
        {
            var path = new[]
                       {
                           0,
                           2
                       };

            m_Converter.Path = path;
            m_Converter.Convert();

            m_Converter.ReleaseConverters();

            Assert.AreEqual(0,
                            m_Converter.Nodes.Count());
        }
        public void ReleaseConvertersCallsReleaseTest()
        {
            var path = new[]
                       {
                           0,
                           2
                       };

            m_Converter.Path = path;
            m_Converter.Convert();

            m_Converter.ReleaseConverters();

            m_Factory.Received(1).Release(Arg.Any <ILineToLineNodeConverter>());
        }
        public void PathRoundtripTest()
        {
            var path = new[]
                       {
                           0,
                           2
                       };

            m_Converter.Path = path;

            NUnitHelper.AssertSequenceEqual(path,
                                            m_Converter.Path,
                                            "Path");
        }
示例#20
0
        /// <summary>
        /// Provides and indication if any values have been set in <see cref="MerchantDescriptor"/>
        /// </summary>
        /// <param name="descriptor">
        /// The descriptor.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public static bool HasValues(this MerchantDescriptor descriptor)
        {
            var values = new[] { descriptor.Name, descriptor.Url, descriptor.Phone };
            var all = string.Join(" ", values).Trim();

            return !string.IsNullOrEmpty(all);
        }
 private static int[][] CreateMatrix()
 {
     var matrix = new[]
                  {
                      new[]
                      {
                          1,
                          2
                      },
                      new[]
                      {
                          1,
                          2
                      }
                  };
     return matrix;
 }
        public void Get_Uses_Name_Override_From_CommandLineNameAttribute()
        {
            const string name = "Testing";
            const string nameOverride = "test";
            const string expected = "1234";
            var commandLine = new[] { "--test=1234" };

            var attribute = new CommandLineNameAttribute(nameOverride);

            var propertyMock = new Mock<PropertyInfo>();
            propertyMock.Setup(x => x.GetCustomAttributes(true)).Returns(new object[] { attribute });

            var source = new DashedCommandLineSource(commandLine);

            string value;
            var result = source.Get(name, propertyMock.Object, out value);

            propertyMock.VerifyAll();
            Assert.IsTrue(result);
            Assert.AreEqual(expected, value);
        }
示例#23
0
		public void IsLastInterval()
		{
			var testTrueTime = new DateTime(2019, 12, DateTime.DaysInMonth(1999, 12), 23, 59, 59, 999) + new TimeSpan(9);

			var testFalseTime = new DateTime(2015, 11, DateTime.DaysInMonth(1999, 11) - 1, 22, 58, 58, 998) + new TimeSpan(8);

			var units = new[]
			{
				TimeUnit.Millisecond, TimeUnit.Second, TimeUnit.Minute, TimeUnit.Hour, TimeUnit.Day
			};

			foreach (var unit in units)
			{
				Assert.IsTrue(testTrueTime.IsLast(unit));

				Assert.IsFalse(testFalseTime.IsLast(unit));
			}
		}
        public void Get_Returns_Null_For_Non_Booean_With_No_Value()
        {
            const string name = "Testing";
            var commandLine = new [] { "--Testing" };

            var propertyMock = new Mock<PropertyInfo>();
            propertyMock.SetupGet(x => x.PropertyType).Returns(typeof(string));

            var source = new DashedCommandLineSource(commandLine);

            string value;
            var result = source.Get(name, propertyMock.Object, out value);

            propertyMock.VerifyGet(x => x.PropertyType);
            Assert.IsNull(value);
            Assert.IsFalse(result);
        }
        public async Task SwitchLoadedInstalledAvailableAsync() {
            var t1 = InUI(() => _packageManagerViewModel.SwitchToLoadedPackagesAsync());
            var t2 = InUI(() => _packageManagerViewModel.SwitchToInstalledPackagesAsync());
            var t3 = InUI(() => _packageManagerViewModel.SwitchToAvailablePackagesAsync());

            await ParallelTools.WhenAll(t1, t2, t3);
            var expected = new [] { "NotAvailable1", "NotAvailable2", "rtvslib1" };

            _packageManagerViewModel.IsLoading.Should().BeFalse();
            _packageManagerViewModel.SelectedPackage.Should().NotBeNull();
            _packageManagerViewModel.Items.Should().Equal(expected, (o, n) => ((IRPackageViewModel)o).Name.EqualsOrdinal(n))
                .And.Contain(_packageManagerViewModel.SelectedPackage);
            
        }