Beispiel #1
0
        public void Modnix3ActionMod()
        {
            MockApi.mockApiVersion = new Version(3, 1);
            PPDefMod.api           = MockApi.Api;
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass();

            repo.AddDef("a", obj);

            ModDefinition mod = JsonToModDef("{flags:[\"Actions\"],guid:\"a\",field:\"boolValue\",value:true}");

            new ModFile("ActionMod.Simple", repo, new MockLogger()).ApplyMod(mod);
            Assert.AreEqual(true, obj.boolValue); // Modified

            mod = JsonToModDef("{flags:[\"Actions\"],guid:\"a\",modletlist:[" +
                               "{field:\"intValue\",value:1234}," +
                               "{field:\"doubleValue\",value:12.34}," +
                               "{field:\"boolValue\",value:false}," +
                               "{field:\"stringValue\",value:\"foobar\"}]}");
            new ModFile("ActionMod.Modlet", repo, new MockLogger()).ApplyMod(mod);
            Assert.AreEqual(1234, obj.intValue);
            Assert.AreEqual(12.34, obj.doubleValue);
            Assert.AreEqual(false, obj.boolValue);
            Assert.AreEqual("foobar", obj.stringValue);
        }
Beispiel #2
0
        protected virtual void Setup()
        {
            MockRepo.Setup(mr => mr.GetByIdAsync(It.IsAny <long>()))
            .ReturnsAsync((long id) => QueryableCollection.FirstOrDefault(x => x.Id == id));

            MockRepo.Setup(mr => mr.Delete(It.IsAny <TEntity>()))
            .Callback <TEntity>(x => QueryableCollection = QueryableCollection.Where(e => e.Id != x.Id));

            MockRepo.Setup(mr => mr.DeleteAsync(It.IsAny <long>()))
            .Callback <long>(id => QueryableCollection = QueryableCollection.Where(e => e.Id != id))
            .ReturnsAsync(true);

            MockRepo.Setup(mr => mr.GetAll(null)).Returns(QueryableCollection);

            MockRepo.Setup(mr => mr.Add(It.IsAny <TEntity>()))
            .Callback <TEntity>(x => QueryableCollection = QueryableCollection.AsEnumerable().Concat(new[] { x }).AsQueryable());

            MockRepo.Setup(mr => mr.AnyAsync(It.IsAny <Expression <Func <TEntity, bool> > >()))
            .ReturnsAsync((Expression <Func <TEntity, bool> > expr) => QueryableCollection.Any(expr.Compile()));

            MockRepo.Setup(mr => mr.CountAsync(It.IsAny <Expression <Func <TEntity, bool> > >()))
            .ReturnsAsync((Expression <Func <TEntity, bool> > expr) => QueryableCollection.Count(expr.Compile()));

            MockRepo.Setup(mr => mr.CountAsync())
            .ReturnsAsync(() => QueryableCollection.Count());

            Items = MockRepo.Object;
        }
Beispiel #3
0
        public void WhenCreatesANewFileObject()
        {
            var file = MockRepo.CreateFile();

            file.Should()
            .NotBeSameAs(file.With());
        }
Beispiel #4
0
        public void BecauseOf()
        {
            var info    = new SubscriptionInformation(_clientId, 0, "", "", _dataUri);
            var message = new SubscriptionAdded {
                Subscription = info
            };

            var saga = new LegacySubscriptionClientSaga(_clientId);

            saga.Bus = new NullServiceBus();

            var data = new OldCacheUpdateRequest(_dataUri);

            saga.RaiseEvent(LegacySubscriptionClientSaga.OldCacheUpdateRequested, data);
            IEnumerable <LegacySubscriptionClientSaga> sagas = new List <LegacySubscriptionClientSaga>
            {
                saga
            };

            MockRepo.Stub(r => r.Where(s => s.CurrentState == LegacySubscriptionClientSaga.Active)).IgnoreArguments().Return(sagas);
            MockEndpointFactory.Expect(e => e.GetEndpoint(saga.Bus.Endpoint.Uri)).Return(saga.Bus.Endpoint);


            Service.Consume(message);
        }
Beispiel #5
0
        public void WhenShouldCreateInstanceWithProvidedParams()
        {
            var file = MockRepo.CreateFile();

            var newFile = file.With(new List <ISourceLine>
            {
                new SourceLine(1,
                               string.Empty,
                               Option <ILineCoverageStats> .None,
                               Option <ILineGitStats> .None)
            },
                                    new FileGitStats(1, 1),
                                    new FileCoverageStats(new FileCoverage(string.Empty,
                                                                           new List <(int lineNumber, int hitCount, bool
                                                                                      branch, string conditionCoverage)
                                                                                     >())));

            newFile.Content.Should()
            .HaveCount(1);
            newFile.GitStats.Match(x => x.LifetimeAuthors,
                                   () => 0)
            .Should()
            .Be(1);
            newFile.CoverageStats.Match(x => x.Coverage,
                                        () => default)
            .Should()
            .NotBeNull();
        }
        private void build_Click(object sender, RoutedEventArgs e)
        {
            int c_proc;

            if ((lb3.Items.Count != 0 || lb5.Items.Count != 0) && (!string.IsNullOrEmpty(b_txtbox.Text)))
            {
                c_proc = Int32.Parse(b_txtbox.Text);
                if (c_proc != 0)
                {
                    b5.IsEnabled = false;

                    Mother_Builder mb = new Mother_Builder();
                    mb.start_builder(c_proc);
                    MockRepo rm = new MockRepo();
                    Thread   repo_thread_start = new Thread(rm.repo_main_thrd);
                    repo_thread_start.Start();
                }
                else
                {
                    MessageBox.Show("Please enter at least one child builder");
                }
            }
            else
            {
                if (lb3.Items.Count == 0 && lb5.Items.Count == 0)
                {
                    MessageBox.Show("Please create test request to start building or select from existing test requests");
                }
                else if (string.IsNullOrEmpty(b_txtbox.Text))
                {
                    MessageBox.Show("Please enter the number of child builders");
                }
            }
        }
Beispiel #7
0
        public void WithShouldCorrectlyOverridePropertiesWithProvidedValues()
        {
            var snapshot = new RepositorySnapshot(string.Empty,
                                                  string.Empty,
                                                  new List <IFile>(),
                                                  string.Empty,
                                                  string.Empty,
                                                  string.Empty,
                                                  default(DateTime),
                                                  0,
                                                  0);

            var newSnapshot = snapshot.With(MockRepo.CreateFiles(3),
                                            "hash",
                                            "path",
                                            DateTime.Today,
                                            "newName");

            newSnapshot.AtHash
            .Match(x => x, () => string.Empty)
            .Should()
            .Be("hash");
            newSnapshot.PathToCoverageResultFile
            .Match(x => x, () => string.Empty)
            .Should()
            .Be("path");
            newSnapshot.CommitCreationDate
            .Match(x => x, () => default)
            .Should()
            .NotBe(default);
Beispiel #8
0
        public void GetSettings()
        {
            var result = Service.GetSettings();

            Assert.That(result, Is.Not.Null);
            MockRepo.Verify(x => x.Get(It.IsAny <string>()), Times.Once);
        }
Beispiel #9
0
        public void TestModletListWithMalformedSteps()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                intValue = 10, boolValue = false
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition
            {
                guid       = "a",
                modletlist = new List <ModletStep> {
                    new ModletStep {
                        field = "intValue", value = 20
                    },
                    new ModletStep {
                        field = null, value = 20
                    },
                    new ModletStep {
                        field = "NoValue", value = null
                    },
                    new ModletStep {
                        field = null, value = null
                    },
                    new ModletStep {
                        field = "boolValue", value = true
                    }
                }
            };
            ModFile f = new ModFile("ModlietListWithMalformedSteps", repo, new MockLogger());

            f.ApplyMod(mod);
            Assert.AreEqual(obj.intValue, 20);
            Assert.IsTrue(obj.boolValue);
        }
Beispiel #10
0
        public void TestMultiArrayValues()
        {
            MockRepo       repo = new MockRepo();
            ArrayTestClass obj  = new ArrayTestClass {
                arr = new ArrayTestClass.Nested[3] {
                    new ArrayTestClass.Nested {
                        nestedValues = new double[2] {
                            7.0, 8.0
                        }
                    },
                    new ArrayTestClass.Nested {
                        nestedValues = new double[3] {
                            17.0, 18.0, 19.0
                        }
                    },
                    new ArrayTestClass.Nested {
                        nestedValues = new double[4] {
                            27.0, 28.0, 29.0, 30.0
                        }
                    }
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "arr[0].nestedValues[1]", value = 10
            };

            new Mod("MultiArrayValues", mod, repo).Apply();
            Assert.AreEqual(obj.arr[0].nestedValues[1], 10.0);
        }
Beispiel #11
0
        public void TestLastArrayObject()
        {
            MockRepo       repo = new MockRepo();
            ArrayTestClass obj  = new ArrayTestClass {
                arr = new ArrayTestClass.Nested[3] {
                    new ArrayTestClass.Nested {
                        value = 7
                    }, new ArrayTestClass.Nested {
                        value = 8
                    }, new ArrayTestClass.Nested {
                        value = 9
                    }
                }
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "arr[2].value", value = 10
            };

            new Mod("LastArray", mod, repo).Apply();
            Assert.AreEqual(obj.arr[0].value, 7);
            Assert.AreEqual(obj.arr[1].value, 8);
            Assert.AreEqual(obj.arr[2].value, 10);
        }
        public void GetLinks()
        {
            var result = Service.GetLinks().ToList();

            Assert.That(result, Is.Not.Null);
            Assert.That(result[0].Id, Is.EqualTo(ExpectedGetLinks[0].Id));
            Assert.That(result[0].LinkEndpoint, Is.EqualTo(ExpectedGetLinks[0].LinkEndpoint));
            Assert.That(result[0].LinkName, Is.EqualTo(ExpectedGetLinks[0].LinkName));
            MockRepo.Verify(x => x.GetAll(), Times.Once);
        }
Beispiel #13
0
        public void SaveNewSetting()
        {
            var model  = F.Create <Setting>();
            var result = Service.SaveSettings(model);

            Assert.That(result, Is.True);
            MockRepo.Verify(x => x.Get(It.IsAny <string>()), Times.Once);
            MockRepo.Verify(x => x.Update(It.IsAny <GlobalSettings>()), Times.Once);
            MockRepo.Verify(x => x.Insert(It.IsAny <GlobalSettings>()), Times.Never);
        }
        public void UpdateLink()
        {
            var dto = new LinksConfigurationDto {
                Id = 1, LinkEndpoint = "www.microsoft.com", LinkName = "Microsoft"
            };
            var result = Service.UpdateLink(dto);

            Assert.That(result, Is.True);
            MockRepo.Verify(x => x.Get(1), Times.Once);
            MockRepo.Verify(x => x.Update(It.IsAny <LinksConfiguration>()), Times.Once);
        }
        public void start_build()
        {
            int            c  = 3;
            Mother_Builder mb = new Mother_Builder();

            mb.start_builder(c);
            MockRepo rm = new MockRepo();
            Thread   repo_thread_start = new Thread(rm.repo_main_thrd);

            repo_thread_start.Start();
        }
Beispiel #16
0
        public void GetSettings()
        {
            var result = Service.GetSettings();

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Enabled, Is.EqualTo(ExpectedGetLinks[0].Enabled));
            Assert.That(result.ShowOnDashboard, Is.EqualTo(ExpectedGetLinks[0].ShowOnDashboard));
            Assert.That(result.Port, Is.EqualTo(ExpectedGetLinks[0].Port));
            Assert.That(result.ApiKey, Is.EqualTo(ExpectedGetLinks[0].ApiKey));
            Assert.That(result.IpAddress, Is.EqualTo(ExpectedGetLinks[0].IpAddress));
            MockRepo.Verify(x => x.GetAll(), Times.Once);
        }
            public void AddNewTodoForTesting()
            {
                ToDoTableRow newToDo = new ToDoTableRow();

                newToDo.Name      = "Fix code.";
                newToDo.Completed = true;
                newToDo.Note      = "Some note";

                MockRepo repo = new MockRepo();

                _repo.Create(newToDo);
            }
Beispiel #18
0
        public void ModifySettings()
        {
            var dto = new SabNzbdSettingsDto {
                Id = 1
            };
            var result = Service.SaveSettings(dto);

            Assert.That(result, Is.True);
            MockRepo.Verify(x => x.Get(1), Times.Once);
            MockRepo.Verify(x => x.Insert(It.IsAny <SabNzbSettings>()), Times.Never);
            MockRepo.Verify(x => x.Update(It.IsAny <SabNzbSettings>()), Times.Once);
        }
        public void InsertSettings()
        {
            var dto = new PlexSettingsDto {
                Id = 2
            };
            var result = Service.SaveSettings(dto);

            Assert.That(result, Is.True);
            MockRepo.Verify(x => x.Get(2), Times.Once);
            MockRepo.Verify(x => x.Insert(It.IsAny <PlexSettings>()), Times.Once);
            MockRepo.Verify(x => x.Update(It.IsAny <PlexSettings>()), Times.Never);
        }
        public void AddLink()
        {
            var dto = new LinksConfigurationDto {
                Id = 1, LinkEndpoint = "google.com", LinkName = "Google"
            };
            var result = Service.AddLink(dto);

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Id, Is.EqualTo(ExpectedLink.Id));
            Assert.That(result.LinkEndpoint, Is.EqualTo(ExpectedLink.LinkEndpoint));
            Assert.That(result.LinkName, Is.EqualTo(ExpectedLink.LinkName));
            MockRepo.Verify(x => x.Insert(It.IsAny <LinksConfiguration>()), Times.Once);
        }
Beispiel #21
0
        public void GetNullSettings()
        {
            var mockRepo = new Mock <ISettingsRepository>();

            mockRepo.Setup(x => x.Get("Test")).Returns(ExpectedLink).Verifiable();
            MockRepo = mockRepo;

            Service = new SettingsService <NzbDashSettings, Setting>(MockRepo.Object, logger.Object);

            var result = Service.GetSettings();

            Assert.That(result.Id, Is.EqualTo(0));
            MockRepo.Verify(x => x.Get(It.IsAny <string>()), Times.Once);
        }
Beispiel #22
0
        public void TestStaticInt()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
            };

            TestClass.Nested.staticIntValue = 0;
            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                cls = "PPDefModifierTests.ApplyModTests+TestClass+Nested, PPDefModifierTests", field = "staticIntValue", value = 5
            };

            new Mod("StaticInt", mod, repo).Apply();
            Assert.AreEqual(TestClass.Nested.staticIntValue, 5);
        }
Beispiel #23
0
        public void TestSimpleInt()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                intValue = 10
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "intValue", value = 5
            };

            new Mod("SimpleInt", mod, repo).Apply();
            Assert.AreEqual(obj.intValue, 5);
        }
Beispiel #24
0
        public void TestSimpleDouble()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                doubleValue = 20.0
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "doubleValue", value = 50.0
            };

            new Mod("SimpleDouble", mod, repo).Apply();
            Assert.AreEqual(obj.doubleValue, 50.0);
        }
        public void CanLoadCarsFromMockRepo()
        {
            IVehicleRepository repo = new MockRepo();
            //var vehicle = repo.GetAll();

            //Assert.AreEqual(7, vehicle.Count);

            //Assert.AreEqual(1, vehicle[0].VehicleId);
            //Assert.AreEqual("Nissan", vehicle[0].Make.MakeName);
            //Assert.AreEqual("Altima", vehicle[0].Model.ModelName);
            //Assert.AreEqual("Red", vehicle[0].Color);
            //Assert.AreEqual("Black", vehicle[0].Interior);
            //Assert.AreEqual("Automatic", vehicle[0].Transmission);
            //Assert.AreEqual("1XP7DU9X48D704313", vehicle[0].VinNumber);
        }
Beispiel #26
0
        public void TestSimpleString()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                stringValue = "foo"
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "stringValue", value = "bar"
            };

            new Mod("SimpleString", mod, repo).Apply();
            Assert.AreEqual(obj.stringValue, "bar");
        }
Beispiel #27
0
        public void Parcel_service_calls_repository_and_returns_grouped_parcels()
        {
            //Arrange
            MockRepo.Setup(p => p.Get <Container>()).Returns(FakeParcels);
            var parcelService = new ParcelService(FakeHandlers, MockRepo.Object, new StandardCriteria());

            //Act
            var result = parcelService.GetGroupedMail();

            //Assert
            var regularDeptGroup = result.ToList().FirstOrDefault(x => x.Handler.Contains("Regular"));

            Assert.IsNotNull(regularDeptGroup);
            Assert.AreEqual(1, regularDeptGroup.Parcels.ToList().Count()); //we expect a parcel record allocated to Regular department
        }
Beispiel #28
0
        public void TestSimpleBool()
        {
            MockRepo  repo = new MockRepo();
            TestClass obj  = new TestClass {
                boolValue = false
            };

            repo.AddDef("a", obj);
            ModDefinition mod = new ModDefinition {
                guid = "a", field = "boolValue", value = 1
            };

            new Mod("SimpleBool", mod, repo).Apply();
            Assert.IsTrue(obj.boolValue);
        }
        static void Main()
        {
            //Console.WriteLine("********Demonstrating the functions of Mock Client*********");
            int s = 3;

            Console.WriteLine("Starting Point");
            //Client cl = new Client();
            //cl.call_client();  // testing the function - call_client()
            Mother_Builder mb = new Mother_Builder();

            mb.start_builder(s);
            MockRepo rm = new MockRepo();
            Thread   repo_thread_start = new Thread(rm.repo_main_thrd);

            repo_thread_start.Start();
        }
Beispiel #30
0
        public async Task Test_IndexService()
        {
            var r            = new MockRepo();
            var indexService = new IndexService(r);
            var emp          = new Employee
            {
                Phones = new[] { "123", "456", "789" }
            };


            var cmd = indexService.CreateUpdateCommand(5, emp);

            await indexService.Handle(cmd);


            //Assert.AreEqual(3, r.Tokens.Count(t => t.SourcePath.Path.ToString() == "$.Phones"));
        }