Skip to content

Commit

Permalink
second filler implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikKasierski committed Nov 29, 2020
1 parent 307ca87 commit bc30203
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 44 deletions.
21 changes: 18 additions & 3 deletions Exercise_1/Exercise_1Tests/Data/Filler/FillerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ namespace Exercise_1.Tests.Data
public class FillerTests
{
[TestMethod()]
public void FillTest()
public void ConstantFillerTest()
{
IFiller filler = new Filler();
DataContext dataContext = new DataContext();
IFiller filler = new ConstantFiller();
IDataContext dataContext = new TestDataContext();

filler.Fill(dataContext);

Assert.AreEqual(dataContext.Users.Count, 5);
Assert.AreEqual(dataContext.Catalogs.Count, 5);
Assert.AreEqual(dataContext.States.Count, 5);
Assert.AreEqual(dataContext.Events.Count, 10);
}

[TestMethod()]
public void RandomFillerTest()
{
IFiller filler = new RandomFiller();
IDataContext dataContext = new TestDataContext();

filler.Fill(dataContext);

Expand All @@ -21,4 +35,5 @@ public void FillTest()
Assert.AreEqual(dataContext.Events.Count, 10);
}
}

}
56 changes: 28 additions & 28 deletions Exercise_1/Exercise_1Tests/Data/Repository/DataRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DataRepositoryTests
[TestMethod()]
public void AddAndGetUserTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

User user = new User("Tomek", "Kowalski");
dataRepository.AddUser(user);
Expand All @@ -24,7 +24,7 @@ public void AddAndGetUserTest()
[TestMethod()]
public void GetUserIncorrectIndexTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Assert.ThrowsException<Exception>(() => dataRepository.GetUser(dataRepository.DataContext.Users.Count));
Assert.ThrowsException<Exception>(() => dataRepository.GetUser(-1));
Expand All @@ -33,7 +33,7 @@ public void GetUserIncorrectIndexTest()
[TestMethod()]
public void GetAllUsersTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

IEnumerable<User> enumerable = dataRepository.GetAllUsers();
List<User> users = enumerable.ToList();
Expand All @@ -52,7 +52,7 @@ public void GetAllUsersTest()
[TestMethod()]
public void UpdateUserTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

User user = new User("Tomek", "Tomkowski");
dataRepository.AddUser(user);
Expand All @@ -71,7 +71,7 @@ public void UpdateUserTest()
[TestMethod()]
public void UpdateUserIncorrectIndexTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

User user = new User("Tomek", "Tomkowski");
dataRepository.AddUser(user);
Expand All @@ -91,7 +91,7 @@ public void UpdateUserIncorrectIndexTest()
[TestMethod()]
public void DeleteUserTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

int numberOfUsersBeforeAdd = dataRepository.DataContext.Users.Count;

Expand All @@ -108,7 +108,7 @@ public void DeleteUserTest()
[TestMethod()]
public void TryingToDeleteUserConnectedWithEventTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

int numberOfUsersBeforeAdd = dataRepository.DataContext.Users.Count;

Expand All @@ -134,7 +134,7 @@ public void TryingToDeleteUserConnectedWithEventTest()
[TestMethod()]
public void AddAndGetCatalogTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Catalog catalog = new Catalog("Autor", "Tytul");
dataRepository.AddCatalog(catalog);
Expand All @@ -145,7 +145,7 @@ public void AddAndGetCatalogTest()
[TestMethod()]
public void GetCatalogIncorrectIndexTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Assert.ThrowsException<Exception>(() => dataRepository.GetCatalog(dataRepository.DataContext.Catalogs.Count));
Assert.ThrowsException<Exception>(() => dataRepository.GetCatalog(-1));
Expand All @@ -154,7 +154,7 @@ public void GetCatalogIncorrectIndexTest()
[TestMethod()]
public void GetAllCatalogsTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

IEnumerable<Catalog> enumerable = dataRepository.GetAllCatalogs();
List<Catalog> catalogs = enumerable.ToList();
Expand All @@ -173,7 +173,7 @@ public void GetAllCatalogsTest()
[TestMethod()]
public void UpdateCatalogTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Catalog catalog = new Catalog("Autor", "Tytul");
dataRepository.AddCatalog(catalog);
Expand All @@ -192,7 +192,7 @@ public void UpdateCatalogTest()
[TestMethod()]
public void UpdateCatalogIncorrectIndexTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Catalog catalog = new Catalog("Autor", "Tytul");
dataRepository.AddCatalog(catalog);
Expand All @@ -212,7 +212,7 @@ public void UpdateCatalogIncorrectIndexTest()
[TestMethod()]
public void DeleteCatalogTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

int numberOfCatalogsBeforeAdd = dataRepository.DataContext.Catalogs.Count;

Expand All @@ -229,7 +229,7 @@ public void DeleteCatalogTest()
[TestMethod()]
public void TryingToDeleteCatalogConnectedWithStateTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

int numberOfCatalogsBeforeAdd = dataRepository.DataContext.Catalogs.Count;

Expand All @@ -249,7 +249,7 @@ public void TryingToDeleteCatalogConnectedWithStateTest()
[TestMethod()]
public void AddAndGetStateTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Catalog catalog = new Catalog("Autor", "Tytul");
dataRepository.AddCatalog(catalog);
Expand All @@ -263,7 +263,7 @@ public void AddAndGetStateTest()
[TestMethod()]
public void GetStateIncorrectIndexTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Assert.ThrowsException<Exception>(() => dataRepository.GetState(dataRepository.DataContext.States.Count));
Assert.ThrowsException<Exception>(() => dataRepository.GetState(-1));
Expand All @@ -272,7 +272,7 @@ public void GetStateIncorrectIndexTest()
[TestMethod()]
public void GetAllStatesTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

IEnumerable<State> enumerable = dataRepository.GetAllStates();
List<State> states = enumerable.ToList();
Expand All @@ -291,7 +291,7 @@ public void GetAllStatesTest()
[TestMethod()]
public void UpdateStateTestCase1()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Catalog catalog = new Catalog("Autor", "Tytul");
dataRepository.AddCatalog(catalog);
Expand All @@ -316,7 +316,7 @@ public void UpdateStateTestCase1()
[TestMethod()]
public void UpdateStateTestCase2_Overload()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Catalog catalog = new Catalog("Autor", "Tytul");
dataRepository.AddCatalog(catalog);
Expand All @@ -341,7 +341,7 @@ public void UpdateStateTestCase2_Overload()
[TestMethod()]
public void UpdateStateIncorrectIndexTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Catalog catalog = new Catalog("Autor", "Tytul");
dataRepository.AddCatalog(catalog);
Expand Down Expand Up @@ -369,7 +369,7 @@ public void UpdateStateIncorrectIndexTest()
[TestMethod()]
public void DeleteStateTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

int numberOfStatesBeforeAdd = dataRepository.DataContext.States.Count;

Expand All @@ -389,7 +389,7 @@ public void DeleteStateTest()
[TestMethod()]
public void TryingToDeleteStateConnectedWithEventTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

int numberOfStatesBeforeAdd = dataRepository.DataContext.States.Count;

Expand All @@ -415,7 +415,7 @@ public void TryingToDeleteStateConnectedWithEventTest()
[TestMethod()]
public void AddAndGetEventTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

User user = new User("Tomek", "Kowalski");
dataRepository.AddUser(user);
Expand All @@ -435,7 +435,7 @@ public void AddAndGetEventTest()
[TestMethod()]
public void GetEventIncorrectIndexTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

Assert.ThrowsException<Exception>(() => dataRepository.GetEvent(dataRepository.DataContext.Events.Count));
Assert.ThrowsException<Exception>(() => dataRepository.GetEvent(-1));
Expand All @@ -444,7 +444,7 @@ public void GetEventIncorrectIndexTest()
[TestMethod()]
public void GetAllEventsTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

IEnumerable<Event> enumerable = dataRepository.GetAllEvents();
List<Event> items = enumerable.ToList();
Expand All @@ -463,7 +463,7 @@ public void GetAllEventsTest()
[TestMethod()]
public void UpdateEventTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

User user = new User("Tomek", "Kowalski");
dataRepository.AddUser(user);
Expand All @@ -489,7 +489,7 @@ public void UpdateEventTest()
[TestMethod()]
public void UpdateEventIncorrectIndexTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

User user = new User("Tomek", "Kowalski");
dataRepository.AddUser(user);
Expand All @@ -516,7 +516,7 @@ public void UpdateEventIncorrectIndexTest()
[TestMethod()]
public void DeleteEventTest()
{
DataRepository dataRepository = new DataRepository(new DataContext(), new Filler());
DataRepository dataRepository = new DataRepository(new DataContext(), new ConstantFiller());

int numberOfEventsBeforeAdd = dataRepository.DataContext.Events.Count;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Exercise_1.Tests.ImplementationsForTests
{
public class Filler : IFiller
public class ConstantFiller : IFiller
{
public void Fill(IDataContext context)
{
Expand Down
56 changes: 56 additions & 0 deletions Exercise_1/Exercise_1Tests/ImplementationsForTests/RandomFiller.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Exercise_1.Data;
using System;
using System.Text;

namespace Exercise_1.Tests.ImplementationsForTests
{
class RandomFiller : IFiller
{
Random random = new Random();

public void Fill(IDataContext context)
{
for (int i = 0; i < 5; i++)
{
context.Users.Add(new User(RandomString(random.Next(5, 10)), RandomString(random.Next(5, 10))));
}

for (int i = 0; i < 5; i++)
{
context.Catalogs.Add(i, new Catalog(RandomString(random.Next(5, 10)), RandomString(random.Next(5, 10))));
}

for (int i = 0; i < 5; i++)
{
context.States.Add(new State(context.Catalogs[i], RandomString(random.Next(5, 10)), new DateTime(random.Next(2015, 2020), random.Next(1, 12), random.Next(1, 27)), true));
}

for (int i = 0; i < 5; i++)
{
context.Events.Add(new CheckoutEvent(context.Users[i], context.States[i], new DateTime(random.Next(2015, 2020), random.Next(1, 12), random.Next(1, 27))));
}

for (int i = 0; i < 5; i++)
{
context.Events.Add(new ReturnEvent(context.Users[i], context.States[i], new DateTime(random.Next(2015, 2020), random.Next(1, 12), random.Next(1, 27))));
}

}

private string RandomString(int length)
{
string alphabet = "abcdefghijklmnopqrstuvwxyz";
int alphabetLength = alphabet.Length;

StringBuilder randomString = new StringBuilder();
Random random = new Random();

for (int i = 0; i < length; i++)
{
randomString.Append(alphabet[random.Next(alphabetLength)]);
}

return randomString.ToString();
}
}
}
Loading

0 comments on commit bc30203

Please sign in to comment.