Skip to content

Commit

Permalink
Irepo not tests yet
Browse files Browse the repository at this point in the history
  • Loading branch information
dsp56001 committed Oct 19, 2021
1 parent de20219 commit 5baf623
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 9 deletions.
5 changes: 3 additions & 2 deletions DogLibrary/IMammal.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System;
using DogLibraryCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DogLibrary
{
public interface IMammal : IAboutable
public interface IMammal : IAboutable, IEntity
{
int Age { get; }
string Name { get; set; }
Expand Down
9 changes: 8 additions & 1 deletion DogLibrary/Mammal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ namespace DogLibrary
{
public abstract class Mammal : IMammal
{
public int Id
{
get;
protected set;

}

public int Age
{
get;
Expand All @@ -31,7 +38,7 @@ public string Name
public int Weight
{
get;
protected set;
set;

}

Expand Down
49 changes: 49 additions & 0 deletions DogLibraryCore/DogLibraryCore/DiagramRepo.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1" MembersFormat="FullSignature">
<Class Name="DogLibraryCore.MammalRepoSimple">
<Position X="3.75" Y="1" Width="4.75" />
<TypeIdentifier>
<HashCode>AAIAAAAAAAAAAAAIAAAABAIAAAAAAAAAAAAAAACAAAA=</HashCode>
<FileName>Repo\MammalRepoSimple.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="DogLibraryCore.EntityBase">
<Position X="9.5" Y="2" Width="1.5" />
<TypeIdentifier>
<HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Repo\IEntity.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="DogLibraryCore.Repository&lt;T&gt;">
<Position X="9.5" Y="3.5" Width="2.75" />
<TypeIdentifier>
<HashCode>AAIAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAII=</HashCode>
<FileName>Repo\Repository.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="DogLibraryCore.Repo.MammalRepo">
<Position X="12.5" Y="3.5" Width="4.25" />
<TypeIdentifier>
<HashCode>AAAAAAAAAIACAAAAAAAAQAAAAACAAAAAAAAAAAAAQAA=</HashCode>
<FileName>Repo\MammalRepo.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Interface Name="DogLibraryCore.IRepository&lt;T&gt;">
<Position X="11.5" Y="0.5" Width="2.5" />
<TypeIdentifier>
<HashCode>AAIAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAII=</HashCode>
<FileName>Repo\IRepository.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="DogLibraryCore.IEntity">
<Position X="9.5" Y="0.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Repo\IEntity.cs</FileName>
</TypeIdentifier>
</Interface>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
3 changes: 1 addition & 2 deletions DogLibraryCore/DogLibraryCore/Repo/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

namespace DogLibraryCore
{
public interface IRepository<T> where T : EntityBase
public interface IRepository<T> //where T : EntityBase
{
T GetById(int id);
IEnumerable<T> List();
void Add(T entity);
void Remove(T entity);
void Update(T entity);
}


Expand Down
41 changes: 41 additions & 0 deletions DogLibraryCore/DogLibraryCore/Repo/MammalRepo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using DogLibrary;
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace DogLibraryCore.Repo
{
public class MammalRepo : IRepository<IMammal>
{

List<IMammal> _repo;

public MammalRepo() : base()
{
_repo = new List<IMammal>();
}

void IRepository<IMammal>.Add(IMammal entity)
{
this._repo.Add(entity);
}

IMammal IRepository<IMammal>.GetById(int id)
{
return this._repo.Where<IMammal>(m => m.Id == id).FirstOrDefault();
}

IEnumerable<IMammal> IRepository<IMammal>.List()
{
return this._repo;
}

void IRepository<IMammal>.Remove(IMammal entity)
{
this._repo.Remove(entity);
}


}
}
5 changes: 5 additions & 0 deletions DogLibraryCore/DogLibraryCore/Repo/MammalRepoSimple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace DogLibraryCore
{
Expand Down Expand Up @@ -39,5 +40,9 @@ public virtual IMammal GetMammalByName(string Name)
return null;
}

public IMammal GetMammalByWeight(int findWeight)
{
return this.Mammals.Where(m => m.Weight == findWeight).FirstOrDefault();
}
}
}
5 changes: 1 addition & 4 deletions DogLibraryCore/DogLibraryCore/Repo/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ public void Remove(T entity)
_repo.Add(entity);

}
public void Update(T entity)
{

}

}
}
79 changes: 79 additions & 0 deletions DogLibraryCore/UnitTestProjectDogMoq/MammalSimpleRepoTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Text;
using DogLibrary;
using DogLibraryCore;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace UnitTestProjectDogMoq
{
[TestClass]
class MammalSimpleRepoTests
{

[TestClass]
public class MammalSimpleRepoTest
{
[TestMethod]
public void TestFindByName()
{
//Arrange
string findName = "fido";
int findWeight = 20;
Dog foundByName, foundByWeight;

MammalRepoSimple repo = new MammalRepoSimple();
repo.Add(new Dog() { Name = findName, Weight = 10 });
repo.Add(new Dog() { Name = "milo", Weight = findWeight });
//act
foundByName = repo.GetMammalByName(findName) as Dog;
foundByWeight = repo.GetMammalByWeight(findWeight) as Dog;

//assert
Assert.AreEqual(findName, foundByName.Name);
Assert.AreEqual(findWeight, foundByWeight.Weight);
}

[TestMethod]
public void TestFindByNameReturnsNullIfNotFound()
{
//Arrange
string findName = "jeff";
int findWeight = 20;
Dog foundByName;

MammalRepoSimple repo = new MammalRepoSimple();
repo.Add(new Dog() { Name = "fido", Weight = 10 });
repo.Add(new Dog() { Name = "milo", Weight = findWeight });
//act
foundByName = repo.GetMammalByName(findName) as Dog;


//assert
Assert.IsNull(foundByName);

}

[TestMethod]
public void TestFindByWeightReturnsNullIfNotFound()
{
//Arrange

int findWeight = 22;
Dog foundByWeight;

MammalRepoSimple repo = new MammalRepoSimple();
repo.Add(new Dog() { Name = "fido", Weight = 10 });
repo.Add(new Dog() { Name = "milo", Weight = 20 });
//act
foundByWeight = repo.GetMammalByWeight(findWeight) as Dog;


//assert
Assert.IsNull(foundByWeight);

}
}

}
}

0 comments on commit 5baf623

Please sign in to comment.