public void TestGetAllEntries() { SetUp(); DBEntry toSave1 = new DBEntry(DateTime.Parse("27.04.2000"), 100, 50, 20); DBEntry toSave2 = new DBEntry(DateTime.Parse("13.09.2000"), 500, 50, 0); DBEntry toSave3 = new DBEntry(DateTime.Parse("29.11.2000"), 120, 40, 10); _toTest.DeleteAllEntries(); List <DBEntry> allEntries = _toTest.GetAllEntries(); Assert.Empty(allEntries); _toTest.SaveDBEntry(toSave1); _toTest.SaveDBEntry(toSave2); _toTest.SaveDBEntry(toSave3); allEntries = _toTest.GetAllEntries(); Assert.Equal(3, allEntries.Count); bool containingOne = false; bool containingTwo = false; bool containingThree = false; foreach (DBEntry dbEntry in allEntries) { containingOne = containingOne || (dbEntry.ToString().Equals(toSave1.ToString())); containingTwo = containingTwo || (dbEntry.ToString().Equals(toSave2.ToString())); containingThree = containingThree || (dbEntry.ToString().Equals(toSave3.ToString())); } Assert.True(containingOne); Assert.True(containingTwo); Assert.True(containingThree); }
public void ToStringTest() { DateTime time = new DateTime(2000, 4, 27); int stepAmount = 100; int pushUpAmount = 50; int sitUpAmount = 10; DBEntry dbEntry = new DBEntry(time, stepAmount, pushUpAmount, sitUpAmount); string expected = "27.04.2000,Steps=100,PushUps=50,SitUps=10"; Assert.Equal(expected, dbEntry.ToString()); }
public void DataOverViewModelConstructorTest() { //Für den ServiceProviderMock //Muss enthalten sein, damit der Mock nicht überschrieben wird IServiceProvider unused = ServiceManager.ServiceProvider; //Feld Infos holen System.Reflection.FieldInfo instance = typeof(ServiceManager).GetField("_serviceProvider", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); //Mocksaufsetzen //ServiceProvider Mock <IServiceProvider> mockSingleton = new Mock <IServiceProvider>(); //Service der gemockt werden soll Mock <IDataBaseConnection> mockDataBase = new Mock <IDataBaseConnection>(); List <DBEntry> entries = new List <DBEntry>(); DBEntry one = new DBEntry( new DateTime(2000, 4, 12), 100, 200, 30); DBEntry two = new DBEntry( new DateTime(2020, 3, 15), 102, 20, 30); entries.Add(one); entries.Add(two); //Verhalten für die Mocks festlegen (Bei Aufruf was zurückgegeben werden soll) mockDataBase.As <IDataBaseConnection>().Setup(x => x.GetMostRecentEntries(30)).Returns(entries); mockSingleton.Setup(x => x.GetService(typeof(IDataBaseConnection))).Returns(mockDataBase.Object); //ServiceProvider anlegen instance.SetValue(null, mockSingleton.Object); //Test ausführen DataOverviewViewModel dataOverview = new DataOverviewViewModel(); //Verifizieren Assert.NotEmpty(dataOverview.TrainingsDataDbEntries); Assert.Equal(2, dataOverview.TrainingsDataDbEntries.Count); DBEntry firsEntry = dataOverview.TrainingsDataDbEntries[0]; Assert.NotNull(firsEntry); Assert.Equal(two.ToString(), firsEntry.ToString()); DBEntry secondEntry = dataOverview.TrainingsDataDbEntries[1]; Assert.NotNull(firsEntry); Assert.Equal(one.ToString(), secondEntry.ToString()); }
public void testOnAppearing() { //Muss enthalten sein, damit der Mock nicht überschrieben wird IServiceProvider unused = ServiceManager.ServiceProvider; //Feld Infos holen System.Reflection.FieldInfo instance = typeof(ServiceManager).GetField("_serviceProvider", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic); //Mocksaufsetzen Mock <IServiceProvider> mockSingleton = new Mock <IServiceProvider>(); Mock <IDataBaseConnection> mockDataBase = new Mock <IDataBaseConnection>(); List <DBEntry> entries = new List <DBEntry>(); DBEntry one = new DBEntry( new DateTime(2000, 4, 12), 100, 200, 30); DBEntry two = new DBEntry( new DateTime(2020, 3, 15), 102, 20, 30); entries.Add(one); entries.Add(two); mockDataBase.As <IDataBaseConnection>().SetupSequence(x => x.GetMostRecentEntries(30)) .Returns(new List <DBEntry>()) .Returns(entries); mockSingleton.Setup(x => x.GetService(typeof(IDataBaseConnection))).Returns(mockDataBase.Object); instance.SetValue(null, mockSingleton.Object); //TestObjekt erstellen DataOverviewViewModel dataOverview = new DataOverviewViewModel(); Assert.Empty(dataOverview.TrainingsDataDbEntries); dataOverview.OnAppearing(null, null); Assert.NotEmpty(dataOverview.TrainingsDataDbEntries); Assert.Equal(2, dataOverview.TrainingsDataDbEntries.Count); DBEntry firsEntry = dataOverview.TrainingsDataDbEntries[0]; Assert.NotNull(firsEntry); Assert.Equal(two.ToString(), firsEntry.ToString()); DBEntry secondEntry = dataOverview.TrainingsDataDbEntries[1]; Assert.NotNull(firsEntry); Assert.Equal(one.ToString(), secondEntry.ToString()); }