コード例 #1
0
 public void SetUp()
 {
     CurrentUser     = new User(Constants.UserId1, "Testy", "*****@*****.**", null);
     AuthServiceMock = new Mock <IAuthenticationService>();
     AuthServiceMock.Setup(x => x.CurrentUser).Returns(CurrentUser);
     DatabaseServiceMock = new MockDatabaseService();
 }
コード例 #2
0
        public void MockDatabaseService_DeleteAndAssertPerformedDelete_Success()
        {
            // Initialize the service
            var data  = new MockDatabaseService(null, typeof(TestQueryProvider));
            var model = new TestModel {
                Col1 = 24, Col2 = "UnitTest"
            };

            // Run the test
            data.Delete("test.delete", model);

            model.Col1 = 25;
            model.Col2 = "TestUnit";
            data.Delete("test.delete", model.Parameters());

            // Check the results
            data.AssertPerformed("test.delete");
            data.AssertPerformedDelete("test.delete");
            data.AssertPerformedDelete("test.delete", 2);
            data.AssertPerformedDelete("test.delete", model.Parameters());

            model.Col1 = 24;
            model.Col2 = "UnitTest";
            data.AssertPerformedDelete("test.delete", 1, model.Parameters());
        }
コード例 #3
0
        public void MockDatabaseService_SelectAndAssertPerformedSelect_Success()
        {
            // Set up some test data
            var result1 = new StubResultSet("col1", "col2")
                          .AddRow(1, "Unit")
                          .AddRow(2, "Tests")
                          .AddRow(3, "Rock");

            var result2 = new StubResultSet("col1", "col2")
                          .AddRow(1, "Yes")
                          .AddRow(2, "They")
                          .AddRow(3, "Do");

            var result3 = new StubResultSet("col1", "col2")
                          .AddRow(1, "Find Those Bugs")
                          .AddRow(2, "Before")
                          .AddRow(3, "They Find You");

            // Initialize the service
            var data  = new MockDatabaseService(new StubDataReader(result1, result2, result3), typeof(TestQueryProvider));
            var model = new TestModel {
                Col1 = 13
            };

            // Check for expected results
            using (var reader = data.Select("test.select"))
            {
                Assert.IsNotNull(reader, "No-Parameter Select should not have returned null");
                Assert.IsTrue(reader.Read(), "No-Parameter Results should not have been empty");
                Assert.AreEqual("Unit", reader[1], "No-Parameter Select returned unexpected results");
            }

            using (var reader = data.Select("test.select", model))
            {
                Assert.IsNotNull(reader, "Database Model Select should not have returned null");
                Assert.IsTrue(reader.Read(), "Database Model results should not have been empty");
                Assert.AreEqual("Yes", reader[1], "Database Model Select returned unexpected results");
            }

            using (var reader = data.Select("test.select", model.Parameters()))
            {
                Assert.IsNotNull(reader, "Parameter Dictionary Select should not have returned null");
                Assert.IsTrue(reader.Read(), "Parameter Dictionary Select results should not have been empty");
                Assert.AreEqual("Find Those Bugs", reader[1], "Parameter Dictionary Select returned unexpected results");
            }

            using (var reader = data.Select("test.select"))
            {
                Assert.IsNotNull(reader, "Empty Select should not have returned null");
                Assert.IsFalse(reader.Read(), "Empty Select results should have been empty");
            }

            // Did we instrument correctly?
            data.AssertPerformed("test.select");
            data.AssertPerformedSelect("test.select");
            data.AssertPerformedSelect("test.select", 4);
            data.AssertPerformedSelect("test.select", model.Parameters());
            data.AssertPerformedSelect("test.select", 2, model.Parameters());
        }
コード例 #4
0
        public void SetUp()
        {
            DatabaseServiceMock = new MockDatabaseService();

            AuthServiceMock = new Mock <IAuthenticationService>();
            AuthServiceMock.Setup(x => x.CurrentUser).Returns(Constants.User1);
            ProfileServiceMock = new Mock <IProfileService>();
            MessagingService   = new MessagingService(AuthServiceMock.Object, DatabaseServiceMock, LoggerMock.Object, ProfileServiceMock.Object);
        }
コード例 #5
0
        public void MockDatabaseService_SequenceAndAssertPerformedSequence_Success()
        {
            var data = new MockDatabaseService(null);

            data.Sequence("unit_test_sequence");

            data.AssertPerformed("unit_test_sequence");
            data.AssertPerformedSequence("unit_test_sequence");
            data.AssertPerformedSequence("unit_test_sequence", 1);
        }
コード例 #6
0
        public void MockDatabaseService_IdentityAndAssertPerformedIdentity_Success()
        {
            var data = new MockDatabaseService(null);

            data.LastIdentity();
            data.LastIdentity();
            data.LastIdentity();

            data.AssertPerformedIdentity();
            data.AssertPerformedIdentity(3);
        }
コード例 #7
0
        public void MockDatabaseService_Constructor_Success()
        {
            var data = new MockDatabaseService(null, typeof(TestQueryProvider));

            Assert.IsNotNull(data, "The Mock Database Service should not have been null");

            // We need the database queries so we can subtract them from the count
            var databaseQueries = new Dictionary <string, DatabaseQuery>();

            new DatabaseQueryProvider().Queries(databaseQueries);

            Assert.AreEqual(4, data.GetQueries().Count - databaseQueries.Count,
                            "There should have been 4 queries loaded");
        }
コード例 #8
0
        public MasterDetailVariableRepositoryViewModel() : base()
        {
            this.WhenAnyValue(a => a.DatabaseService)
            .Subscribe(a => { service.OnNext(new(a)); });

            ChangeRepositoryCommand = ReactiveCommand.Create <bool, Unit>((a) =>
            {
                if (DatabaseService is LiteDbRepository service)
                {
                    DatabaseService = new MockDatabaseService();
                }
                else
                {
                    DatabaseService = new LiteDbRepository(new(typeof(ReactiveFields), nameof(ReactiveFields.Id)));
                }

                return(Unit.Default);
            });
        }