public void CheckThirdParty_WhenExecute_AndConcurrencyException_ThenLogWarning() { queues.Add(GenerateVoucher()); ExpectContextToCreateTransaction(); ExpectContextToReturnQueues(queues); dipsDbContext.Setup(x => x.SaveChanges()) .Throws(new OptimisticConcurrencyException()); var sut = CreatePollingJob(); sut.Execute(null); logger.Verify(x => x.Warning(It.IsAny <string>(), queues.Single().S_BATCH)); }
public void In_memory_DbSet_can_be_used_for_Attach() { var set = new InMemoryDbSet<Product>(); var product = new Product(); Assert.Same(product, set.Attach(product)); Assert.Same(product, set.Single()); }
public void GetVouchersInformation_WhenExecute_AndConcurrencyException_ThenLogWarning() { dipsRequests.Add(GenerateDipsRequest()); ExpectContextToCreateTransaction(); ExpectContextToReturnQueues(queues); ExpectContextToReturnDipsRequests(dipsRequests); dipsDbContext.Setup(x => x.SaveChanges()) .Throws(new OptimisticConcurrencyException()); var sut = CreatePollingJob(); sut.Execute(null); logger.Verify(x => x.Warning(It.IsAny<string>(), dipsRequests.Single().guid_name)); }
public void WhenExecute_AndConcurrencyException_ThenLogWarning() { queues.Add(new DipsQueue { ResponseCompleted = false, S_LOCATION = "CodelineCorrectDone", S_LOCK = "0", S_SDATE = "01/01/15", S_STIME = "12:12:12" }); ExpectContextToCreateTransaction(); ExpectContextToReturnQueues(queues); dipsDbContext.Setup(x => x.SaveChanges()) .Throws(new OptimisticConcurrencyException()); var sut = CreatePollingJob(); sut.Execute(null); logger.Verify(x => x.Warning(It.IsAny <string>(), queues.Single().S_BATCH)); }
public void Signup() { // SETUP var d = CreateData(); string providerName = ((ICollection)Membership.Providers).Cast <ProviderBase>().First().Name; MembershipUser user = new MembershipUser(providerName, d.Username, string.Empty, d.Email, string.Empty, string.Empty, false, false, DateTime.Now, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue); TestProfile profile = new TestProfile(); Mock <IPermissionsService> permissionMock = new Mock <IPermissionsService>(MockBehavior.Strict); permissionMock.Setup(f => f.GetUser(d.Username)).Returns <MembershipUser>(null); permissionMock.Setup(f => f.CreateUser(d.Username, d.Password, d.Email)).Returns(user).Verifiable(); permissionMock.Setup(f => f.SetCurrentUser(d.Username)).Verifiable(); permissionMock.Setup(f => f.UpdateUser(user)); permissionMock.Setup(f => f.GetProfile(d.Username)).Returns(profile); permissionMock.Setup(f => f.RoleExists(AccountController.APPLICANT_ROLE)).Returns(true); permissionMock.Setup(f => f.AddUserToRole(d.Username, AccountController.APPLICANT_ROLE)).Verifiable(); InMemoryDbSet <Member> members = new InMemoryDbSet <Member>(); InMemoryDbSet <PersonContact> contacts = new InMemoryDbSet <PersonContact>(); InMemoryDbSet <SarUnit> units = new InMemoryDbSet <SarUnit>(new[] { new SarUnit { Id = d.Units.First() } }); InMemoryDbSet <Kcsar.Database.Model.UnitApplicant> applicants = new InMemoryDbSet <Kcsar.Database.Model.UnitApplicant>(); Mock <IKcsarContext> dbMock = new Mock <IKcsarContext>(MockBehavior.Strict); dbMock.SetupGet(f => f.Members).Returns(members); dbMock.SetupGet(f => f.PersonContact).Returns(contacts); dbMock.SetupGet(f => f.Units).Returns(units); dbMock.SetupGet(f => f.UnitApplicants).Returns(applicants); dbMock.Setup(f => f.SaveChanges()).Returns(4); Mock <IWebHostingService> hostMock = new Mock <IWebHostingService>(MockBehavior.Strict); hostMock.Setup(f => f.ReadFile("EmailTemplates\\new-account-verification.html")).Returns("%Username%\n%VerifyLink%\n%WebsiteContact%"); hostMock.Setup(f => f.GetApiUrl("Account", "Verify", d.Username, true)).Returns("THE-URL"); hostMock.SetupGet(f => f.FeedbackAddress).Returns("feedback"); Mock <IEmailService> emailMock = new Mock <IEmailService>(MockBehavior.Strict); string mailBody = null; emailMock .Setup(f => f.SendMail(d.Email, string.Format(AccountController.MAIL_SUBJECT_TEMPLATE, WebStrings.DatabaseName), It.IsAny <string>())) .Callback((Action <string, string, string>)((e, s, b) => mailBody = b)) .Verifiable(); // TEST AccountController c = new AccountController(emailMock.Object, dbMock.Object, permissionMock.Object, hostMock.Object, new ConsoleLogger()); var result = c.Signup(d); // VERIFY Assert.AreEqual("OK", result); permissionMock.VerifyAll(); emailMock.VerifyAll(); var newMember = members.Single(); Assert.AreEqual(d.Firstname, newMember.FirstName, "firstname"); Assert.AreEqual(d.Lastname, newMember.LastName, "lastname"); Assert.AreEqual(d.BirthDate, newMember.BirthDate, "dob"); var applicant = applicants.Single(); }