public void LocateNeighbours()
        {
            var db = new LocalityQueryProximityDatabase<object>(Vector3.Zero, new Vector3(10, 10, 10), new Vector3(2, 2, 2));

            Dictionary<object, Vector3> positionLookup = new Dictionary<object, Vector3>();

            var xyz000 = CreateToken(db, new Vector3(0, 0, 0), positionLookup);
            var xyz100 = CreateToken(db, new Vector3(1, 0, 0), positionLookup);
            CreateToken(db, new Vector3(3, 0, 0), positionLookup);

            var list = new List<object>();
            xyz000.FindNeighbors(Vector3.Zero, 2, list);

            Assert.AreEqual(2, list.Count);
            Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(0, 0, 0)));
            Assert.AreEqual(1, list.Count(a => positionLookup[a] == new Vector3(1, 0, 0)));

            //Check tokens handle being disposed twice
            xyz000.Dispose();
            xyz000.Dispose();

            list.Clear();
            xyz100.FindNeighbors(Vector3.Zero, 1.5f, list);

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(new Vector3(1, 0, 0), positionLookup[list[0]]);
        }
        public async Task TestMaxItemCount()
        {
            var nextItem = 0;
            var pool = new PipelinedPool<int>(() => TaskPort.FromResult(++nextItem), null, new PipelinedPoolOptions
            {
                MaxRequestsPerItem = 10,
                TargetItemCount = 2,
            });

            var items = new List<IPooledItem<int>>();
            for (int i = 0; i < 20; ++i)
            {
                var task = pool.Borrow();
                Assert.AreEqual(true, task.IsCompleted);
                var item = await task;
                items.Add(item);
            }
            Assert.AreEqual(20, items.Count);
            Assert.AreEqual(10, items.Count(v => v.Item == 1));
            Assert.AreEqual(10, items.Count(v => v.Item == 2));

            var waiter = pool.Borrow();
            Assert.AreEqual(false, waiter.IsCompleted);

            items.First().Dispose();
            Assert.AreEqual(true, waiter.IsCompleted);
            foreach (var item in items.Skip(1))
            {
                item.Dispose();
            }
            waiter.Result.Dispose();
        }
Example #3
0
 public void GetRandomGenderTest() 
 {
     var maxTests = 1000000;
     var genders = new List<string>();
     for (var i = 0; i < maxTests; i++) {
         genders.Add(RandomInfoGenerator.GetRandomGender(i));
     }
     var malesCount = genders.Count(s=> s == "Male");
     Assert.IsTrue(malesCount < genders.Count());
 }
 public void ForEachTest()
 {
     int N = 10;
     List<A> items = new List<A>(N);
     for (int i = 0; i < N; ++i)
         items.Add(new A());
     Assert.AreEqual(0, items.Count(a => a.Visited));
     items.ForEach(a => a.Visit());
     Assert.AreEqual(N, items.Count(a => a.Visited));
 }
        private void TestLogEntries(List<LogEntry> expectedLogEntries, List<LogEntry> actualLogEntries)
        {
            Assert.AreEqual(expectedLogEntries.Count(), actualLogEntries.Count(), "Log counts not equal");

            for (int i = 0; i < expectedLogEntries.Count(); i++)
            {
                Assert.AreEqual(expectedLogEntries.ElementAt(i).Message, actualLogEntries.ElementAt(i).Message);
                Assert.AreEqual(expectedLogEntries.ElementAt(i).LoggerName, actualLogEntries.ElementAt(i).LoggerName);
                Assert.AreEqual(expectedLogEntries.ElementAt(i).Level, actualLogEntries.ElementAt(i).Level);
            }
        }
        public void ViewModel_Observed()
        {
            var propertyNames = new List<string>();
            var vm = new MyViewModel();
            vm.PropertyChanged += (sender, args) => propertyNames.Add(args.PropertyName);
            vm.ViewModelProperty = new MyViewModel { StringProperty = "inner vm" };

            Assert.AreEqual(1, propertyNames.Count(s => s == "ViewModelProperty"));
            Assert.AreEqual(0, propertyNames.Count(s => s == "StringProperty"));

            vm.ViewModelProperty.StringProperty = "new value";
            Assert.AreEqual(2, propertyNames.Count(s => s == "ViewModelProperty"));
            Assert.AreEqual(0, propertyNames.Count(s => s == "StringProperty"));
        }
        public async Task LoadAdaptersNameTooLongAsyncTest()
        {
            //Arrange 
            var dbConnection = new StubIEntityContextConnection { NameOrConnectionStringGet = () => "am-LoadAdaptersNameTooLongAsyncTest" };
            Database.SetInitializer(new CreateFreshDbInitializer());

            var logEntries = new List<LogEntry>();
            var log = new StubIFeedback<LogEntry>
            {
                ReportAsyncT0CancellationToken = (e, c) =>
                {
                    Console.WriteLine(e.ToString());
                    logEntries.Add(e);
                    return Task.FromResult(0);
                }
            };

            var longNameAdapter = new StubZvsAdapter
            {
                AdapterGuidGet = () => Guid.Parse("a0f912a6-b8bb-406a-360f-1eb13f50aae4"),
                NameGet = () => "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque magna diam, pellentesque et orci eget, pellentesque iaculis odio. Ut ultrices est sapien, ac pellentesque odio malesuada a. Etiam in neque ullamcorper massa gravida ullamcorper vel a posuere.",
                DescriptionGet = () => "",
                OnSettingsCreatingAdapterSettingBuilder = (s) => Task.FromResult(0),
                OnDeviceTypesCreatingDeviceTypeBuilder = (s) => Task.FromResult(0)
            };

            var adapterManager = new AdapterManager(new List<ZvsAdapter>() { longNameAdapter }, dbConnection, log);
            //act
            await adapterManager.StartAsync(CancellationToken.None);

            //assert 
            Assert.IsTrue(logEntries.Count(o => o.Level == LogEntryLevel.Error) == 1, "Expected 1 error");
        }
        public void ReturnOnlyLocationsWithGravityLessThan105PercentOfStandard()
        {
            var mocks = new Rhino.Mocks.MockRepository();
            var db = (null as ILocationRepository).Create(mocks);

            int locationCount = 100.GetRandom(50);
            var allLocations = new List<Location>();
            for (int i = 0; i < locationCount; i++)
                allLocations.Add((null as Location).Create());

            TestContext.WriteLine("{0} locations in data store", allLocations.Count());

            Rhino.Mocks
                .Expect.Call(db.GetLocations())
                .Repeat.Any()
                .Return(allLocations);

            mocks.ReplayAll();

            var target = new Engine(db);
            var actual = target.Scout();
            TestContext.WriteLine("{0} locations returned from target", actual.Count());

            foreach (var location in actual)
                Assert.IsTrue(location.Gravity < 1.05);

            mocks.VerifyAll();
        }
Example #9
0
 public void REPORT_FAILURE(string greekName, Average.Type averageType,
     double runningAccumulator, int pastFixings,
     List<Date> fixingDates, StrikedTypePayoff payoff,
     Exercise exercise, double s, double q, double r,
     Date today, double v, double expected,
     double calculated, double tolerance)
 {
     Assert.Fail(exercise + " "
     + exercise
     + " Asian option with "
     + averageType + " and "
     + payoff + " payoff:\n"
     + "    running variable: "
     + runningAccumulator + "\n"
     + "    past fixings:     "
     + pastFixings + "\n"
     + "    future fixings:   " + fixingDates.Count() + "\n"
     + "    underlying value: " + s + "\n"
     + "    strike:           " + payoff.strike() + "\n"
     + "    dividend yield:   " + q + "\n"
     + "    risk-free rate:   " + r + "\n"
     + "    reference date:   " + today + "\n"
     + "    maturity:         " + exercise.lastDate() + "\n"
     + "    volatility:       " + v + "\n\n"
     + "    expected   " + greekName + ": " + expected + "\n"
     + "    calculated " + greekName + ": " + calculated + "\n"
     + "    error:            " + Math.Abs(expected - calculated)
     + "\n"
     + "    tolerance:        " + tolerance);
 }
 public void hasSameNumberOfStations()
 {
     ciudades = new List<string>();
     ciudades.Add(final[3]);
     for (int i = 3; i < final.Length;i++)
     {
         bool exists = false;
         if ((i + 8) < final.Length)
         {
             i = i + 7;
         }
         else
         {
             continue;
         }
         for (int j = 0; j < ciudades.Count(); j++)
             {
                 if (final[i].Equals(ciudades.ElementAt(j)))
                 {
                     exists = true;
                 }
         }
         if (!exists)
         {
             ciudades.Add(final[i]);
         }
         i--;
     }
     Assert.AreEqual(13,ciudades.Count);
 }
 public void Should_get_types_except_for_stop_point()
 {
     var typeNames = new List<string>();
     var visitor = GetRelayVisiterForTypes(typeNames);
     visitor.GoUntil(typeof(ObservableCollection<>), () => typeNames.Count == 5);
     Assert.AreEqual(5, typeNames.Count());
 }
Example #12
0
        public async Task All_Text_Is_Removed_And_Readded_When_Replace_Option_Selected()
        {
            // Assort
            var store = new List<ForwardTextCandidate>(from x in InputTextItems.Take(2) select new ForwardTextCandidate { Text = x });
            var repository = CreateFakeRepository(store);

            var svc = new Mock<CsvFileTextService<ForwardTextCandidate>>();
            svc.Setup(x => x.Import(It.IsAny<string>(), MergeWithExistingRecordsPolicy.Replace, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater))
                .Callback<string, MergeWithExistingRecordsPolicy, IBaseRepository<ForwardTextCandidate>, Func<string, ForwardTextCandidate>, Func<ForwardTextCandidate, string, bool>, Action<ForwardTextCandidate, string>>
                ((path, opc, rep, creator, locator, updater) =>
                {
                    rep.Get().ToList().ForEach(x => rep.Delete(x));
                    InputTextItems.ToList().ForEach(x => rep.Save(new ForwardTextCandidate { Text = x }));
                })
                .Returns(Task.FromResult<ImportTextResult>(new ImportTextResult { Success = true, InsertedRecords = InputTextItems.Length }));

            // Act
            var result = await svc.Object.Import(string.Empty, MergeWithExistingRecordsPolicy.Replace, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater);

            // Assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(InputTextItems.Length, store.Count());

            var index = 0;
            store.ForEach(x => Assert.AreEqual(x.Text, InputTextItems[index++]));

            repository.Verify(x => x.Create(It.IsAny<ForwardTextCandidate>()), Times.Exactly(3));
        }
Example #13
0
        public async Task All_Provided_Text_Is_Added_When_The_Append_Option_Is_Selected()
        {
            // Assort
            var store = new List<ForwardTextCandidate>();
            var repository = new MockRepository(MockBehavior.Default).Create<Repository<ForwardTextCandidate>>(new Mock<ISession>().Object);
            repository.Setup(x => x.Get()).Returns(store.AsQueryable());
            repository.Setup(x => x.Save(It.IsAny<IQueryable<ForwardTextCandidate>>())).Callback<IQueryable<ForwardTextCandidate>>(items => store.AddRange(items));

            var svc = new Mock<CsvFileTextService<ForwardTextCandidate>>();
            svc.Setup(x => x.Import(It.IsAny<string>(), MergeWithExistingRecordsPolicy.Append, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater))
                .Callback<string, MergeWithExistingRecordsPolicy, IBaseRepository<ForwardTextCandidate>,  Func<string, ForwardTextCandidate>, Func<ForwardTextCandidate, string, bool>, Action<ForwardTextCandidate, string>>
                ((path, opc, rep, creator, locator, updater) =>
                {
                    var itemsToAdd = new List<ForwardTextCandidate>();
                    InputTextItems.ToList().ForEach(x => itemsToAdd.Add(new ForwardTextCandidate { Text = x }));
                    rep.Save(itemsToAdd.AsQueryable());
                })
                .Returns(Task.FromResult<ImportTextResult>(new ImportTextResult { Success = true, InsertedRecords = InputTextItems.Length }));
            
            // Act
            var result = await svc.Object.Import(string.Empty, MergeWithExistingRecordsPolicy.Append, repository.Object, NullEntityCreator, NullEntityLocator, NullEntityUpdater);

            // Assert
            Assert.IsTrue(result.Success);
            Assert.AreEqual(InputTextItems.Length, store.Count());

            var index = 0;
            store.ForEach(x => Assert.AreEqual(x.Text, InputTextItems[index++]));
        }
        public void RuleSetOnlyNotifiesWhenStrictlyNeccessary()
        {
            var changedprops = new List<string>();
            var persister = new XmlPersister( new RuleSetXmlSerializer(), new StreamFactory( "data.xml" ), 2000 );
            var rs = persister.RecreateRuleSet();
            rs.PropertyChanged += ( s, e ) => changedprops.Add( e.PropertyName );

            var controller = new AlchemyController( rs );

            var rule = controller.RecommendNewRule();
            rule.Result = new[] { new Element( "alpha" ) };
            controller.ReportChangedRule( rule );

            Assert.AreEqual( 1, changedprops.Count( p => p.Equals( "FoundElements" ) ) );
            Assert.AreEqual( 1, changedprops.Count( p => p.Equals( "Rules" ) ) );
        }
Example #15
0
        public void CanParseMultiTabledDeps2()
        {
            //arrange
            var query = "SELECT players.id,players.homeworld_id,orbital_objects.star_system_id,(SELECT foo from bar) FROM players,second" +
                        "\n,"+
                        "\nthird" +
                        "\n  , fourth ,fifth"+
                        "\nJOIN colonies ON colonies.orbital_object_id = players.homeworld_id AND colonies.player_id={0}" +
                        "\nJOIN orbital_objects ON orbital_objects.id = colonies.orbital_object_id" +
                        "\nWHERE homeworld_id NOT NULL";

            var expected = new List<string>(){
                "colonies",
                "players",
                "orbital_objects",
                "second",
                "third",
                "fourth",
                "fifth",
                "bar"
            };

            //act

            var result = SQLParser.ExtractTableDependencies(query);

            //assert
            Assert.IsTrue(!expected.Any(e => !result.Contains(e)));

            Assert.AreEqual(expected.Count(), result.Count());
        }
Example #16
0
        public void AddRoomPoints_CallWebAPI_NotFail_Test()
        {
            var context = new MyEventsContext();
            var manualResetEvent = new ManualResetEvent(false);
            var exceptionResult = default(Exception);

            var eventDefinition = context.EventDefinitions.First();
            List<Client.RoomPoint> points = new List<Client.RoomPoint>()
            {
                new Client.RoomPoint() { EventDefinitionId = eventDefinition.EventDefinitionId, PointX = 0, PointY = 0 },
                new Client.RoomPoint() { EventDefinitionId = eventDefinition.EventDefinitionId, PointX = 1, PointY = 2 },
                new Client.RoomPoint() { EventDefinitionId = eventDefinition.EventDefinitionId, PointX = 3, PointY = 4 },
            };

            string urlPrefix = testContextInstance.Properties[TestContext.AspNetDevelopmentServerPrefix + "webapiserver"].ToString();
            var service = new Client.MyEventsClient(urlPrefix);
            service.SetAccessToken(MyEventsToken.CreateToken(eventDefinition.OrganizerId));
            IAsyncResult asynResult = service.RoomPointService.AddRoomPointsAsync(points, (HttpStatusCode code) =>
            {
                using (var contextAfter = new MyEventsContext())
                {
                    var actual = contextAfter.RoomPoints.Where(q => q.EventDefinitionId == eventDefinition.EventDefinitionId).Count();
                    TestHelper.ValidateResult(points.Count(), actual, manualResetEvent, ref exceptionResult);
                }
            });

            TestHelper.WaitAll(manualResetEvent, ref exceptionResult);
        }
        public void ParseText_DuplicateKeys_Succeeds()
        {
            //arrange
            const string apiText = @"STATUS=S,When=1375833030,Code=9,Msg=3 GPU(s) - 16 PGA(s),Description=bfgminer 3.1.3|GPU=0,Name=OCL,ID=0,ProcID=0,Enabled=N,Status=Alive,Temperature=51.00,MHS av=0.000,MHS 5s=0.000,Accepted=0,Rejected=0,Hardware Errors=0,Utility=0.000,Last Share Pool=-1,Last Share Time=0,Total MH=0.0000,Diff1 Work=0,Difficulty Accepted=0.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=0.00000000,Last Valid Work=1375832874,Fan Speed=1153,Fan Percent=30,GPU Clock=1050,Memory Clock=1450,GPU Voltage=1.250,GPU Activity=96,Powertune=20,Intensity=D|GPU=1,Name=OCL,ID=1,ProcID=0,Enabled=N,Status=Alive,Temperature=52.00,MHS av=0.000,MHS 5s=0.000,Accepted=0,Rejected=0,Hardware Errors=0,Utility=0.000,Last Share Pool=-1,Last Share Time=0,Total MH=0.0000,Diff1 Work=0,Difficulty Accepted=0.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=0.00000000,Last Valid Work=1375832874,Fan Speed=1099,Fan Percent=30,GPU Clock=1050,Memory Clock=1450,GPU Voltage=1.250,GPU Activity=96,Powertune=20,Intensity=D|GPU=2,Name=OCL,ID=2,ProcID=0,Enabled=N,Status=Alive,Temperature=3.00,MHS av=0.000,MHS 5s=0.000,Accepted=0,Rejected=0,Hardware Errors=0,Utility=0.000,Last Share Pool=-1,Last Share Time=0,Total MH=0.0000,Diff1 Work=0,Difficulty Accepted=0.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=0.00000000,Last Valid Work=1375832874,Fan Speed=-1,Fan Percent=-1,GPU Clock=304,Memory Clock=667,GPU Voltage=0.937,GPU Activity=0,Powertune=0,Intensity=D|PGA=0,Name=ICA,ID=0,ProcID=0,Enabled=Y,Status=Alive,MHS av=340.649,MHS 5s=221.067,Accepted=9,Rejected=0,Hardware Errors=1,Utility=3.997,Last Share Pool=0,Last Share Time=1375833026,Total MH=46027.3340,Diff1 Work=10,Difficulty Accepted=9.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833026|PGA=1,Name=ICA,ID=1,ProcID=0,Enabled=Y,Status=Alive,MHS av=337.982,MHS 5s=208.247,Accepted=15,Rejected=0,Hardware Errors=1,Utility=6.670,Last Share Pool=0,Last Share Time=1375833029,Total MH=45603.5042,Diff1 Work=16,Difficulty Accepted=15.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833028|PGA=2,Name=ICA,ID=2,ProcID=0,Enabled=Y,Status=Alive,MHS av=350.839,MHS 5s=214.519,Accepted=9,Rejected=0,Hardware Errors=1,Utility=4.008,Last Share Pool=0,Last Share Time=1375833025,Total MH=47271.8785,Diff1 Work=10,Difficulty Accepted=9.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833024|PGA=3,Name=ICA,ID=3,ProcID=0,Enabled=Y,Status=Alive,MHS av=319.447,MHS 5s=207.144,Accepted=10,Rejected=0,Hardware Errors=1,Utility=4.456,Last Share Pool=0,Last Share Time=1375833017,Total MH=43008.9243,Diff1 Work=11,Difficulty Accepted=10.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833017|PGA=4,Name=ICA,ID=4,ProcID=0,Enabled=Y,Status=Alive,MHS av=349.226,MHS 5s=209.267,Accepted=9,Rejected=0,Hardware Errors=0,Utility=4.126,Last Share Pool=0,Last Share Time=1375833027,Total MH=45701.6753,Diff1 Work=9,Difficulty Accepted=9.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833027|PGA=5,Name=ICA,ID=5,ProcID=0,Enabled=Y,Status=Alive,MHS av=343.349,MHS 5s=214.790,Accepted=8,Rejected=0,Hardware Errors=0,Utility=3.671,Last Share Pool=0,Last Share Time=1375833022,Total MH=44897.5644,Diff1 Work=8,Difficulty Accepted=8.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833022|PGA=6,Name=ICA,ID=6,ProcID=0,Enabled=Y,Status=Alive,MHS av=313.481,MHS 5s=201.904,Accepted=15,Rejected=0,Hardware Errors=0,Utility=6.892,Last Share Pool=0,Last Share Time=1375833016,Total MH=40939.2524,Diff1 Work=15,Difficulty Accepted=15.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833016|PGA=7,Name=ICA,ID=7,ProcID=0,Enabled=Y,Status=Alive,MHS av=348.244,MHS 5s=215.738,Accepted=6,Rejected=0,Hardware Errors=0,Utility=2.757,Last Share Pool=0,Last Share Time=1375833021,Total MH=45471.7777,Diff1 Work=6,Difficulty Accepted=6.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833021|PGA=8,Name=ICA,ID=8,ProcID=0,Enabled=Y,Status=Alive,MHS av=348.954,MHS 5s=222.509,Accepted=12,Rejected=0,Hardware Errors=0,Utility=5.515,Last Share Pool=0,Last Share Time=1375833026,Total MH=45557.9005,Diff1 Work=12,Difficulty Accepted=12.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833026|PGA=9,Name=ICA,ID=9,ProcID=0,Enabled=Y,Status=Alive,MHS av=320.507,MHS 5s=205.080,Accepted=10,Rejected=0,Hardware Errors=0,Utility=4.596,Last Share Pool=0,Last Share Time=1375833017,Total MH=41837.2451,Diff1 Work=10,Difficulty Accepted=10.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=1.00000000,Last Valid Work=1375833017|PGA=10,Name=ICA,ID=10,ProcID=0,Enabled=N,Status=Initialising,MHS av=0.000,MHS 5s=0.000,Accepted=0,Rejected=0,Hardware Errors=0,Utility=0.000,Last Share Pool=-1,Last Share Time=0,Total MH=0.0000,Diff1 Work=0,Difficulty Accepted=0.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=0.00000000,Last Valid Work=1375832879|PGA=11,Name=ICA,ID=11,ProcID=0,Enabled=N,Status=Initialising,MHS av=0.000,MHS 5s=0.000,Accepted=0,Rejected=0,Hardware Errors=0,Utility=0.000,Last Share Pool=-1,Last Share Time=0,Total MH=0.0000,Diff1 Work=0,Difficulty Accepted=0.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=0.00000000,Last Valid Work=1375832879|PGA=12,Name=MMQ,ID=0,ProcID=0,Enabled=N,Status=Initialising,Temperature=26.00,MHS av=0.000,MHS 5s=0.000,Accepted=0,Rejected=0,Hardware Errors=0,Utility=0.000,Last Share Pool=-1,Last Share Time=0,Total MH=0.0000,Diff1 Work=0,Difficulty Accepted=0.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=0.00000000,Last Valid Work=1375832886,Frequency=210.000,Cool Max Frequency=250.000,Max Frequency=250.000,Hardware Errors=0,Valid Nonces=0|PGA=13,Name=MMQ,ID=0,ProcID=1,Enabled=N,Status=Initialising,Temperature=26.00,MHS av=0.000,MHS 5s=0.000,Accepted=0,Rejected=0,Hardware Errors=0,Utility=0.000,Last Share Pool=-1,Last Share Time=0,Total MH=0.0000,Diff1 Work=0,Difficulty Accepted=0.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=0.00000000,Last Valid Work=0,Frequency=210.000,Cool Max Frequency=250.000,Max Frequency=250.000,Hardware Errors=0,Valid Nonces=0|PGA=14,Name=MMQ,ID=0,ProcID=2,Enabled=N,Status=Initialising,Temperature=26.00,MHS av=0.000,MHS 5s=0.000,Accepted=0,Rejected=0,Hardware Errors=0,Utility=0.000,Last Share Pool=-1,Last Share Time=0,Total MH=0.0000,Diff1 Work=0,Difficulty Accepted=0.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=0.00000000,Last Valid Work=0,Frequency=210.000,Cool Max Frequency=250.000,Max Frequency=250.000,Hardware Errors=0,Valid Nonces=0|PGA=15,Name=MMQ,ID=0,ProcID=3,Enabled=N,Status=Initialising,Temperature=25.00,MHS av=0.000,MHS 5s=0.000,Accepted=0,Rejected=0,Hardware Errors=0,Utility=0.000,Last Share Pool=-1,Last Share Time=0,Total MH=0.0000,Diff1 Work=0,Difficulty Accepted=0.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=0.00000000,Last Valid Work=0,Frequency=210.000,Cool Max Frequency=250.000,Max Frequency=250.000,Hardware Errors=0,Valid Nonces=0|";
            List<DeviceInformationResponse> deviceInformation = new List<DeviceInformationResponse>();

            //act
            DeviceInformationParser.ParseTextForDeviceInformation(apiText, deviceInformation);

            //assert
            Assert.IsTrue(deviceInformation.Count > 0);
            Assert.IsTrue(deviceInformation.Count(d => d.AverageHashrate > 0.00) > 0);
            Assert.IsTrue(deviceInformation.Count(d => d.CurrentHashrate > 0.00) > 0);
            Assert.IsTrue(deviceInformation.Count(d => d.AcceptedShares > 0.00) > 0);
            Assert.IsTrue(deviceInformation.Count(d => d.Temperature > 0.00) > 0);
        }
Example #18
0
        public void EtwFileSourceTest()
        {
            var observable = EtwObservable.FromFiles(FileName);
            var source = new TimeSource<EtwNativeEvent>(observable, e => e.TimeStamp);

             var parsed = from p in source
                        where p.Id == 2
                        select p.TimeStamp;

            var buf = parsed.Take(13).Buffer(TimeSpan.FromSeconds(1), source.Scheduler);

            var list = new List<IList<DateTimeOffset>>();
            ManualResetEvent completed = new ManualResetEvent(false);

            buf.Subscribe(
                t => list.Add(t),
                ()=>completed.Set());

            source.Connect();
            completed.WaitOne();

            Assert.AreEqual(2, list.Count());
            Assert.AreEqual(7, list.First().Count);
            Assert.AreEqual(6, list.Skip(1).First().Count);
        }
Example #19
0
        public void Get_Object_fromPager_User_Match_To_DB()
        {
            var users = new List<staff>{new staff{
                Email = "*****@*****.**",
                FirstName = "andrew",
                LastName = "nick",
                ID = 3
            },
            new staff{
                Email = "*****@*****.**",
                FirstName = "aasdndrew",
                LastName = "nicasdk",
                ID = 30}
            };

            Mock<IStaffDAO> mockStaffDAO = new Mock<IStaffDAO>();
            mockStaffDAO.Setup(m => m.Get()).Returns(users);
            StaffBL staffBL = new StaffBL(mockStaffDAO.Object);
            var result = staffBL.Get(5, 0, "");
            Assert.AreEqual(users.Count(), result.staffMembers.Count());
            IEnumerator<staff> e1 = users.GetEnumerator();
            IEnumerator<staff> e2 = result.staffMembers.GetEnumerator();

            while (e1.MoveNext() && e2.MoveNext())
            {
                Assert.AreEqual(e1.Current, e2.Current);
            }
        }
Example #20
0
        public void InterrogaServizio()
        {
            int chiamate = 0;
            List<FarmaciaFake> farmacie = new List<FarmaciaFake>();

            Task t = new Task(new Action(() =>
            {
                bool loadMore = true;

                while (ogdiConsumer.LoadNextDataChunkAsync(5, farmacie).Result == true && loadMore == true)
                {
                    chiamate++;

                    if (chiamate > 5)
                        break;
                }
            }));

            t.Start();
            t.Wait();

            Assert.IsTrue(chiamate > 0);

            int count = farmacie.Count();
            Assert.IsTrue(count > 0);

            int randomIndex = (new Random()).Next(count-1);
            var farmacia = farmacie[randomIndex];

            Assert.IsFalse(string.IsNullOrEmpty(farmacia.partitaiva));
        }
        public void Compare(List<XElement> expectXElements, List<XElement> actualXElements)
        {
            Assert.AreEqual(expectXElements.Count(), actualXElements.Count(), "Unexpected number of Csdl files!");

            // extract EntityContainers into one place
            XElement expectedContainers = CsdlElementExtractor.ExtractElementByName(expectXElements, "EntityContainer");
            XElement actualContainers = CsdlElementExtractor.ExtractElementByName(actualXElements, "EntityContainer");

            // compare just the EntityContainers
            Console.WriteLine("Expected: " + expectedContainers.ToString());
            Console.WriteLine("Actual: " + actualContainers.ToString());
            csdlXElementComparer.Compare(expectedContainers, actualContainers);

            foreach (var expectXElement in expectXElements)
            {
                string schemaNamespace = expectXElement.Attribute("Namespace") == null ? string.Empty : expectXElement.Attribute("Namespace").Value;
                XElement actualXElement = actualXElements.FirstOrDefault(e => schemaNamespace == (e.Attribute("Namespace") == null ? string.Empty : e.Attribute("Namespace").Value));

                Assert.IsNotNull(actualXElement, "Cannot find schema for '{0}' in result Csdls!", schemaNamespace);

                Console.WriteLine("Expected: " + expectXElement.ToString());
                Console.WriteLine("Actual: " + actualXElement.ToString());

                csdlXElementComparer.Compare(expectXElement, actualXElement);
                // TODO: Extend the TaupoModelComparer for the Constructible APIs instead of using CsdlXElementComparer. 
            }
        }
Example #22
0
        public void TestXmlSerializer_IEnumerable()
        {
            IEnumerable<int> list = new List<int>() { 1, 2, 3, 4 };

            var xml = XmlSerializer.Serialize(list);

            var roundTrip = (XmlSerializer.Deserialize(xml) as IEnumerable).Cast<int>();

            Assert.IsNotNull(roundTrip);
            Assert.AreEqual<int>(list.Count(), roundTrip.Count());
            int count = list.Count();
            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual<int>(list.Skip(i).First(), roundTrip.Skip(i).First());
            }
        }
 public void AddSimpleTimedTaskTest()
 {
     input = "add morning 8 AM TASK";
     output = testStrParser.ParseStringIntoWords(input);
     List<string> outputCheck = new List<string>();
     outputCheck.Add("add");
     outputCheck.Add("morning");
     outputCheck.Add("8 AM");
     outputCheck.Add("TASK");
     Assert.IsTrue(output.Count()==outputCheck.Count);
     for (int i = 0; i < output.Count(); i++ )
     {
         Assert.AreEqual(outputCheck[i], output[i]);
     }
     return;
 }
 public void AddComplicatedDatedTaskTest()
 {
     input = "add  milk jan 23rd 2016 to feb 29th 2016";
     output = testStrParser.ParseStringIntoWords(input);
     List<string> outputCheck = new List<string>();
     outputCheck.Add("add");
     outputCheck.Add("milk");
     outputCheck.Add("jan 23rd 2016");
     outputCheck.Add("to");
     outputCheck.Add("feb 29th 2016");
     Assert.IsTrue(output.Count() == outputCheck.Count);
     for (int i = 0; i < output.Count(); i++)
     {
         Assert.AreEqual(outputCheck[i], output[i]);
     }
     return;
 }
Example #25
0
        public RepositoryMock()
        {
            List<Reply> replies = new List<Reply>
            {

                new Reply(){Body = "bdy1", Id = 1, TopicId = 1, Created = DateTime.Now},
                new Reply(){Body = "bdy2", Id = 2, TopicId = 1, Created = DateTime.Now},
                new Reply(){Body = "bdy3", Id = 3, TopicId = 1, Created = DateTime.Now},
                new Reply(){Body = "bdy4", Id = 4, TopicId = 1, Created = DateTime.Now}
            };

            Mock<IMsgRepo> mockRepo = new Mock<IMsgRepo>();
            mockRepo.Setup(m => m.GetReplies()).Returns(replies.AsQueryable);

            mockRepo.Setup(m => m.FindById(
                It.IsAny<int>()))
                .Returns((int i) => replies.Single(x => x.Id == i));

            mockRepo.Setup(m => m.DeleteReply(It.IsAny<int>()))
                .Returns(
                    (int deleteId) =>
                    {
                        var replyToDelete = replies.Single(r => r.Id == deleteId);
                        replies.Remove(replyToDelete);
                        return true;
                    });

            mockRepo.Setup(m => m.InsertReply(
                It.IsAny<Reply>())).Returns(
                    (Reply target) =>
                    {
                        DateTime now = DateTime.Now;
                        if (target.Id.Equals(default(int)))
                        {
                            target.Created = now;
                            target.Id = replies.Count() + 1;
                            replies.Add(target);

                        }
                        else
                        {
                            var orig = replies.Single(r => r.Id == target.Id);
                            if (orig == null)
                                return false;

                            orig.Body = target.Body;
                            orig.Created = now;
                            orig.TopicId = target.TopicId;

                        }
                        return true;
                    }

                );

            MockRepo = mockRepo.Object;
        }
Example #26
0
 public void ListarJunta()
 {
     //listamos
     SOAPJuntasService.JuntaServiceClient objjuntaservice = new SOAPJuntasService.JuntaServiceClient();
     List<SOAPJuntasService.ListaJuntas> ObjListaJuntas = new List<SOAPJuntasService.ListaJuntas>();
     ObjListaJuntas = objjuntaservice.listarJuntas("2013-01-01", "2014-12-31");
     //debe traer valores
     Assert.AreNotEqual(0, ObjListaJuntas.Count());
 }
        public void RuleSetNotifiesOnPropertyChanged()
        {
            var changedprops = new List<string>();
            var r = new RuleSet();
            r.PropertyChanged += ( s, e ) => changedprops.Add( e.PropertyName );

            var controller = new AlchemyController( r );
            controller.RegisterNewElement( "fire" );
            var rule = controller.RecommendNewRule();
            rule.Result = new[] { new Element( "water" ) };

            controller.ReportChangedRule( rule );

            Assert.AreEqual( 2, changedprops.Count( p => p.Equals( "FoundElements" ) ) );
            Assert.AreEqual( 2, r.FoundElements.Count() );
            Assert.AreEqual( 1, changedprops.Count( p => p.Equals( "Rules" ) ) );
            Assert.AreEqual( 1, r.Rules.Count() );
        }
Example #28
0
        /// <summary>
        /// Constructor
        /// </summary>
        public MoqTests()
        {
            // Create Products
            IList<Product> products = new List<Product>
            {
                new Product { ProductId = 1, Name = "C# Unleashed", Description = "Short description here", Price = 49.99 },
                new Product { ProductId = 2, Name = "ASP.Net Unleashed", Description = "Short description here", Price = 59.99 },
                new Product { ProductId = 3, Name = "Silverlight Unleashed", Description = "Short description here", Price = 29.99 }
            };

            // Mock the Products Repository using Moq
            Mock<IProductRepository> mockProductRepository = new Mock<IProductRepository>();

            // Return all the products
            mockProductRepository.Setup(mr => mr.FindAll()).Returns(products);

            // return a product by Id
            mockProductRepository.Setup(mr => mr.FindById(It.IsAny<int>())).Returns((int i) => products.Where(x => x.ProductId == i).Single());

            // return a product by Name
            mockProductRepository.Setup(mr => mr.FindByName(It.IsAny<string>())).Returns((string s) => products.Where(x => x.Name == s).Single());

            // Allows us to test saving a product

            mockProductRepository.Setup(mr => mr.Save(It.IsAny<Product>())).Returns(
                (Product target) =>
                {
                    DateTime now = DateTime.Now;

                    if (target.ProductId.Equals(default(int)))
                    {
                        target.DateCreated = now;
                        target.DateModified = now;
                        target.ProductId = products.Count() + 1;
                        products.Add(target);
                    }
                    else
                    {
                        var original = products.Where(q => q.ProductId == target.ProductId).Single();

                        if (original == null)
                        {
                            return false;
                        }

                        original.Name = target.Name;
                        original.Price = target.Price;
                        original.Description = target.Description;
                        original.DateModified = now;
                    }
                    return true;

                });

            // Complete the setup of our Mock Product Repository
            this.MockProductsRepository = mockProductRepository.Object;
        }
        public void ParseText_RussianCulture_Succeeds()
        {
            //arrange
            Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("ru-RU");
            const string apiText = @"STATUS=S,When=1373818935,Code=9,Msg=2 GPU(s) - 0 ASC(s) - 0 PGA(s) - ,Description=cgminer 3.3.1|GPU=0,Enabled=Y,Status=Alive,Temperature=66.00,Fan Speed=3257,Fan Percent=70,GPU Clock=1065,Memory Clock=1650,GPU Voltage=1.090,GPU Activity=99,Powertune=0,MHS av=0.64,MHS 1s=0.58,Accepted=24,Rejected=0,Hardware Errors=0,Utility=145.71,Intensity=20,Last Share Pool=0,Last Share Time=1373818934,Total MH=6.2915,Diff1 Work=85,Difficulty Accepted=90.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=2.00000000,Last Valid Work=1373818934|GPU=1,Enabled=Y,Status=Alive,Temperature=75.00,Fan Speed=3242,Fan Percent=70,GPU Clock=1065,Memory Clock=1650,GPU Voltage=1.090,GPU Activity=99,Powertune=0,MHS av=0.64,MHS 1s=0.58,Accepted=30,Rejected=0,Hardware Errors=0,Utility=182.14,Intensity=20,Last Share Pool=0,Last Share Time=1373818934,Total MH=6.2915,Diff1 Work=95,Difficulty Accepted=102.00000000,Difficulty Rejected=0.00000000,Last Share Difficulty=2.00000000,Last Valid Work=1373818934|";
            List<DeviceInformationResponse> deviceInformation = new List<DeviceInformationResponse>();

            //act
            DeviceInformationParser.ParseTextForDeviceInformation(apiText, deviceInformation);

            //assert
            Assert.IsTrue(deviceInformation.Count > 0);
            Assert.IsTrue(deviceInformation.Count(d => d.AverageHashrate > 0.00) > 0);
            Assert.IsTrue(deviceInformation.Count(d => d.CurrentHashrate > 0.00) > 0);
            Assert.IsTrue(deviceInformation.Count(d => d.AcceptedShares > 0.00) > 0);
            Assert.IsTrue(deviceInformation.Count(d => d.Temperature > 0.00) > 0);
        }
        public void OnTraversing_AcceptProcessor_TraversesAllWordsInLinearFashoin()
        {
            IEnumerable<string> words = new List<string>() { "Our", "time", "in", "the", "world", "is", "a", "loan", "we", "must", "pay", "it", "with", "interest" };
            IWordProcessor processor = Rhino.Mocks.MockRepository.GenerateMock<IWordProcessor>();

            StandardWordTraverser traverser = new StandardWordTraverser(words);
            traverser.AcceptProcessor(processor);

            processor.AssertWasCalled(p => p.ProcessEach(Arg<string>.Is.Anything), options => options.Repeat.Times(words.Count()));
        }