public void DnaService_SaveAsync_WrongParameters_Fails() { //Arrange DnaService service = GetDnaService(); //Action && Asserts Assert.ThrowsExceptionAsync <ArgumentException>(() => service.SaveAsync(null)); }
public void DnaService_GetByChainAsync_WrongParameters_Fails() { //Arrange DnaService service = GetDnaService(); string[] emptyArray = { }; //Action && Asserts Assert.ThrowsExceptionAsync <ArgumentException>(() => service.GetByChainAsync(null)); Assert.ThrowsExceptionAsync <ArgumentException>(() => service.GetByChainAsync(emptyArray)); }
public async Task DnaService_GetHumansCountAsync_5Humans_Succeeds() { //Arrange DnaService service = GetDnaService(); _dnaRepositoryMock.Setup(x => x.GetHumansCount(It.IsAny <ISession>())).Returns(5).Verifiable(); //Action int result = await service.GetHumansCountAsync(); //Asserts Assert.AreEqual(5, result); _sessionFactoryMock.Verify(x => x.OpenSession(), Times.Once); _dnaRepositoryMock.Verify(x => x.GetHumansCount(It.IsAny <ISession>()), Times.Once); }
public async Task DnaService_SaveAsync_EmptyCollection_Succeeds() { //Arrange DnaService service = GetDnaService(); ICollection <Dna> dnas = new List <Dna>(); _dnaRepositoryMock.Setup(x => x.GetByChainString(It.IsAny <ISession>(), It.IsAny <string>())).Returns(new Dna()).Verifiable(); _dnaRepositoryMock.Setup(x => x.Save(It.IsAny <ISession>(), It.IsAny <Dna>())).Verifiable(); //Action await service.SaveAsync(dnas); //Asserts _sessionFactoryMock.Verify(x => x.OpenSession(), Times.Once); _sessionMock.Verify(x => x.BeginTransaction(), Times.Once); _transactionMock.Verify(x => x.Commit(), Times.Once); _dnaRepositoryMock.Verify(x => x.GetByChainString(It.IsAny <ISession>(), It.IsAny <string>()), Times.Never); _dnaRepositoryMock.Verify(x => x.Save(It.IsAny <ISession>(), It.IsAny <Dna>()), Times.Never); }
public async Task DnaService_GetByChainAsync_ValidArray_Succeeds() { //Arrange DnaService service = GetDnaService(); string[] chain = { "AA", "CC" }; Dna dna = new Dna() { Id = Guid.NewGuid(), ChainString = "AA,CC", IsMutant = false }; _dnaRepositoryMock.Setup(x => x.GetByChainString(It.IsAny <ISession>(), It.IsAny <string>())).Returns(dna).Verifiable(); //Action Dna result = await service.GetByChainAsync(chain); //Asserts Assert.IsNotNull(result); _sessionFactoryMock.Verify(x => x.OpenSession(), Times.Once); _dnaRepositoryMock.Verify(x => x.GetByChainString(It.IsAny <ISession>(), It.IsAny <string>()), Times.Once); }