public void Should_Throw_If_Package_File_Does_Not_Exist()
        {
            // Given
            var fixture = new UniversalPackagePusherFixture {
                Settings = { Package = "./path/does/not/exist.upack" }
            };

            // When
            var result = Record.Exception(() => fixture.Run());

            // Then
            ExtraAssert.IsCakeExceptionWithMessage(result, s => s.StartsWith("Universal package file does not exist at"));
        }
        public void Should_Throw_If_Target_Is_Null()
        {
            // Given
            var fixture = new UniversalPackagePusherFixture {
                Settings = { Target = null }
            };

            // When
            var result = Record.Exception(() => fixture.Run());

            // Then
            ExtraAssert.IsCakeException(result, "Required setting Target not specified.");
        }
        public void Should_Throw_If_UPack_Executable_Was_Not_Found()
        {
            // Given
            var fixture = new UniversalPackagePusherFixture();

            fixture.GivenDefaultToolDoNotExist();

            // When
            var result = Record.Exception(() => fixture.Run());

            // Then
            ExtraAssert.IsCakeException(result, "UPack: Could not locate executable.");
        }
        public void Should_Throw_If_Credentials_Are_Not_Valid()
        {
            // Given
            var fixture = new UniversalPackagePusherFixture {
                Settings = { UserName = "******", Password = "" }
            };

            // When
            var result = Record.Exception(() => fixture.Run());

            // Then
            ExtraAssert.IsCakeException(result, "Both username and password must be specified for authentication");
        }
        public void Should_Throw_If_Source_Is_Null_Or_Empty(string source)
        {
            // Given
            var fixture = new UniversalPackageInstallerFixture {
                Settings = { Source = source }
            };

            // When
            var result = Record.Exception(() => fixture.Run());

            // Then
            ExtraAssert.IsCakeException(result, "Required setting Source not specified.");
        }
        public void Should_Throw_If_Unauthorized(string assetUri)
        {
            using (var server = FluentMockServer.Start())
            {
                server.Given(Request.Create().WithPath(assetUri).UsingGet())
                .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.Unauthorized));

                var asset  = new ProGetAssetDownloader(_config);
                var result = Record.Exception(() =>
                                              asset.GetSingleAsset($"http://localhost:{server.Ports[0]}{assetUri}", new FilePath(Path.GetTempPath())));
                ExtraAssert.IsCakeException(result, "Authorization to ProGet server failed; Credentials were incorrect, or not supplied.");
            }
        }
        public void Should_Throw_If_Process_Was_Not_Started()
        {
            // Given
            var fixture = new UniversalPackagePusherFixture();

            fixture.GivenProcessCannotStart();

            // When
            var result = Record.Exception(() => fixture.Run());

            // Then
            ExtraAssert.IsCakeException(result, "UPack: Process was not started.");
        }
        public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code()
        {
            // Given
            var fixture = new UniversalPackagePusherFixture();

            fixture.GivenProcessExitsWithCode(1);

            // When
            var result = Record.Exception(() => fixture.Run());

            // Then
            ExtraAssert.IsCakeException(result, "UPack: Process returned an error (exit code 1).");
        }
        public void Should_Throw_If_Settings_Are_Null()
        {
            // Given
            var fixture = new UniversalPackagePusherFixture {
                Settings = null
            };

            // When
            var result = Record.Exception(() => fixture.Run());

            // Then
            ExtraAssert.IsArgumentNullException(result, "settings");
        }
        public void Should_Throw_If_Resolver_Is_Null()
        {
            // Given
            var fixture = new UniversalPackagePusherFixture();

            fixture.Resolver = null;

            // When
            var result = Record.Exception(() => fixture.Run());

            // Then
            ExtraAssert.IsArgumentNullException(result, "resolver");
        }
コード例 #11
0
        public void TestShiftOpen()
        {
            RandomGeneratorExtensions.GetGetNewRandom = () => new RandomGenerator(116542346);

            // create a new empty route.
            var testCount = 10;
            var customers = new List <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            var route     = new Optimization.Tours.Tour(customers, null);

            // remove customers.
            int testIdx = 0;

            while (testIdx < testCount)
            {
                var customerIdx = RandomGeneratorExtensions.GetRandom().Generate(
                    customers.Count);
                var insertIdx = RandomGeneratorExtensions.GetRandom().Generate(
                    customers.Count - 2);
                if (customerIdx <= insertIdx)
                {
                    insertIdx = insertIdx + 1;
                }

                var customer = customers[customerIdx];
                var insert   = customers[insertIdx];
                if (customer != route.First &&
                    customer != route.Last)
                {
                    if (customerIdx < insertIdx)
                    {
                        customers.Insert(insertIdx + 1, customer);
                        customers.RemoveAt(customerIdx);
                    }
                    else
                    {
                        customers.RemoveAt(customerIdx);
                        customers.Insert(insertIdx + 1, customer);
                    }

                    route.ShiftAfter(customer, insert);

                    Assert.AreEqual(customers.Count, route.Count);
                    Assert.AreEqual(0, route.First);
                    Assert.AreEqual(null, route.Last);

                    ExtraAssert.ItemsAreEqual(customers, route);

                    testIdx++;
                }
            }
        }
コード例 #12
0
        public void BasicWorld()
        {
            Resource res;

            PlarfGame.Instance.Initialize(new Size(50, 50));

            // resources
            res = PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.ResourceTemplates["Stones"], new Location(0, 0)) as Resource;
            PlarfGame.Instance.World.MarkResourceForHarvest(res);

            ExtraAssert.Throws <LocationAlreadyInUseException>(() => PlarfGame.Instance.World.AddPlaceable(
                                                                   PlarfGame.Instance.ResourceTemplates["Stones"], new Location(0, 1)));

            res = PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.ResourceTemplates["Tree"], new Location(0, 2)) as Resource;
            PlarfGame.Instance.World.MarkResourceForHarvest(res);
            res = PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.ResourceTemplates["Tree"], new Location(1, 2)) as Resource;
            PlarfGame.Instance.World.MarkResourceForHarvest(res);

            res = PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.ResourceTemplates["Stones"], new Location(0, 3)) as Resource;
            PlarfGame.Instance.World.MarkResourceForHarvest(res);

            ExtraAssert.Throws <LocationAlreadyInUseException>(() => PlarfGame.Instance.World.AddPlaceable(
                                                                   PlarfGame.Instance.ResourceTemplates["Stones"], new Location(0, 4)));

            // storage
            PlarfGame.Instance.World.AddPlaceable(PlarfGame.Instance.BuildingClasses["Storage"], new Location(5, 0), new Size(3, 5));

            // some basic bounds tests
            for (int x = 0; x <= 1; ++x)
            {
                for (int y = 0; y <= 1; ++y)
                {
                    Assert.IsTrue(PlarfGame.Instance.World.GetPlaceables(x, y).Cast <Resource>().Single().Name == "Stones");
                }
            }
            Assert.IsTrue(PlarfGame.Instance.World.GetPlaceables(0, 2).Cast <Resource>().Single().Name == "Tree");

            // actors
            var h = PlarfGame.Instance.World.AddActor(PlarfGame.Instance.HumanTemplate, "H", new Location(2, 2)) as Human;

            //Game.Instance.World.AddActor(Game.Instance.HumanTemplate, new Location(0, 2));

            // simulation loop
            for (int cnt = 0; cnt < 50000; ++cnt)
            {
                PlarfGame.Instance.Run(TimeSpan.FromMilliseconds(1000.0 / 30));
            }
        }
コード例 #13
0
        public void TestReplaceClosed()
        {
            var customers = new List <int>(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            var route     = new Optimization.Tours.Tour(customers, 0);

            route.Replace(0, 10);

            ExtraAssert.ItemsAreEqual(new int[] { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, route);

            route.Replace(5, 15);

            ExtraAssert.ItemsAreEqual(new int[] { 10, 1, 2, 3, 4, 15, 6, 7, 8, 9 }, route);

            route.Replace(9, 19);

            ExtraAssert.ItemsAreEqual(new int[] { 10, 1, 2, 3, 4, 15, 6, 7, 8, 19 }, route);
        }
        public void Should_Throw_Exception_When_Asset_Push_Fails_As_Put(string assetUri)
        {
            using (var server = FluentMockServer.Start())
            {
                server.Given(Request.Create().WithPath(assetUri).UsingPut())
                .RespondWith(Response.Create().WithStatusCode(HttpStatusCode.BadRequest));

                var asset    = new ProGetAssetPusher(_log, _config);
                var tempFile = new FilePath($"{Path.GetTempPath()}Should_Throw_Exception_When_Asset_Push_Fails_As_Put.txt");

                if (File.Exists(tempFile.FullPath))
                {
                    File.Delete(tempFile.FullPath);
                }

                using (var fileStream = new FileStream(tempFile.FullPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
                {
                    fileStream.SetLength(4194304);
                }
                var result = Record.Exception(() => asset.Publish(tempFile, $"http://localhost:{server.Ports[0]}{assetUri}"));

                ExtraAssert.IsCakeException(result, "Upload failed. This request would have overwritten an existing package.");
            }
        }
            public void Should_Throw_If_Package_Is_Null_Or_Empty(string package)
            {
                var ex = Record.Exception(() => new UniversalPackageInstallSettings(package, "http://proget.com/upack/feed", "./folder"));

                ExtraAssert.IsArgumentException(ex, "package", "Value cannot be null or empty.");
            }
            public void Should_Throw_If_Source_Is_Null(string source)
            {
                var ex = Record.Exception(() => new UniversalPackageInstallSettings("Test.Package", source, "./folder"));

                ExtraAssert.IsArgumentException(ex, "source", "Value cannot be null or empty.");
            }
            public void Should_Throw_If_TargetDirectory_Is_Null()
            {
                var ex = Record.Exception(() => new UniversalPackageInstallSettings("Test.Package", "http://proget.com/upack/feed", null));

                ExtraAssert.IsArgumentNullException(ex, "targetDirectory");
            }
コード例 #18
0
            public void Should_Throw_If_TargetDirectory_Is_Null()
            {
                var ex = Record.Exception(() => new UniversalPackagePushSettings("./path/to/file.upack", null));

                ExtraAssert.IsArgumentException(ex, "target", "Value cannot be null or empty.");
            }
            public void Should_Throw_If_Metadata_FilePath_Is_Null()
            {
                var ex = Record.Exception(() => new UniversalPackagePackSettings(null, "./folder"));

                ExtraAssert.IsArgumentNullException(ex, "metadataFilePath");
            }
            public void Should_Throw_If_SourceDirectory_Is_Null()
            {
                var ex = Record.Exception(() => new UniversalPackagePackSettings("./path/to/file.uspec", null));

                ExtraAssert.IsArgumentNullException(ex, "sourceDirectory");
            }
            public void Should_Throw_If_TargetDirectory_Is_Null()
            {
                var ex = Record.Exception(() => new UniversalPackageUnpackSettings("./path/to/file.upack", null));

                ExtraAssert.IsArgumentNullException(ex, "targetDirectory");
            }