public async Task Execute_Should_UpdateEntityStatus() { // arrange var cancellationToken = CancellationToken.None; var dbContextFactory = new DefaultDbContextFactory(); var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory(); var generator = new CoreDbGenerator(unitOfWorkFactory, dbContextFactory); var handler = new UpdateEntityStatusHandler(unitOfWorkFactory, dbContextFactory); using (var _ = unitOfWorkFactory.Create()) { // arrange var item1 = new EntityStatus { Uid = Guid.NewGuid(), DisplayOrder = 1, Code = "drafted", Name = "Draft" }; var item2 = new EntityStatus { Uid = Guid.NewGuid(), DisplayOrder = 2, Code = "published", Name = "Published" }; await generator.InsertEntityStatus(item1, cancellationToken); await generator.InsertEntityStatus(item2, cancellationToken); // act var request = new UpdateEntityStatus { EntityTypeCode = generator.EntityTypeCode, EntityUid = generator.EntityUid, Item = new EntityStatus { Uid = item1.Uid, Code = "draft", Name = "The Draft", DisplayOrder = 10 } }; var result = await handler.Handle(request, cancellationToken); // assert Assert.IsNotNull(result); Assert.AreEqual(1, result.AffectedRows); var statuses = await generator.GetEntityStatuses(cancellationToken); Assert.AreEqual(2, statuses.Rows.Count); Assert.AreEqual(2, statuses.Rows[0].DisplayOrder); Assert.AreEqual("published", statuses.Rows[0].Code); Assert.AreEqual("Published", statuses.Rows[0].Name); Assert.AreEqual(10, statuses.Rows[1].DisplayOrder); Assert.AreEqual("draft", statuses.Rows[1].Code); Assert.AreEqual("The Draft", statuses.Rows[1].Name); } }
public async Task Execute_Should_DeleteEntityStatus() { // arrange var cancellationToken = CancellationToken.None; var dbContextFactory = new DefaultDbContextFactory(); var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory(); var generator = new CoreDbGenerator(unitOfWorkFactory, dbContextFactory); var handler = new DeleteEntityStatusHandler(unitOfWorkFactory, dbContextFactory); using (var _ = unitOfWorkFactory.Create()) { // arrange var uids = new List <Guid>(); for (var i = 0; i < 42; i++) { var insertResult = await generator.InsertEntityStatus(new EntityStatus { Uid = Guid.NewGuid(), Code = "status_code_" + i, Name = "Status Name " + i }, cancellationToken); // ReSharper disable once PossibleInvalidOperationException uids.Add(insertResult.Uid.Value); } // act var request = new DeleteEntityStatus { EntityTypeCode = generator.EntityTypeCode, EntityUid = generator.EntityUid, Uids = uids.Take(3).ToList() }; var result = await handler.Handle(request, cancellationToken); // assert Assert.IsNotNull(result); Assert.AreEqual(3, result.AffectedRows); var statuses = await generator.GetEntityStatuses(cancellationToken); Assert.AreEqual(39, statuses.Rows.Count); foreach (var uid in request.Uids) { Assert.IsNull(statuses.Rows.FirstOrDefault(x => x.Uid == uid)); } } }
public async Task GetEntityStatusList_Should_ReturnList() { // arrange var cancellationToken = CancellationToken.None; var dbContextFactory = new DefaultDbContextFactory(); var unitOfWorkFactory = new TransactionScopeUnitOfWorkFactory(); var entityStatusRepository = new DbEntityStatusRepository(dbContextFactory); var generator = new CoreDbGenerator(unitOfWorkFactory, dbContextFactory); var handler = new GetEntityStatusListHandler(entityStatusRepository); using (var _ = unitOfWorkFactory.Create()) { // arrange for (var i = 0; i < 42; i++) { await generator.InsertEntityStatus(new EntityStatus { Code = "status_code_" + i, Name = "Status Name " + i }, cancellationToken); } // act var request = new GetEntityStatusList { EntityTypeCode = generator.EntityTypeCode, EntityUid = generator.EntityUid }; var result = await handler.Handle(request, cancellationToken); // assert Assert.IsNotNull(result); Assert.AreEqual(10, result.Rows.Count); Assert.AreEqual(42, result.TotalCount); } }