Ejemplo n.º 1
0
        public void AdminsFanZone_Add_2()
        {
            // Arrange
            var theater = new Theater {
                Name = "Arena"
            };

            _unitOfWork.Theaters.Add(theater);

            var user1 = Utils.GetTestUser(1);
            var user2 = Utils.GetTestUser(2);
            var user3 = Utils.GetTestUser(3);

            _unitOfWork.Users.AddRange(new ISofAUser[] { user1, user2, user3 });
            _unitOfWork.SaveChanges();

            // Act
            _adminService.AddFanZoneAdmin(theater.TheaterId, user1);
            _adminService.AddFanZoneAdmin(theater.TheaterId, user2);
            _adminService.AddTheaterAdmin(theater.TheaterId, user3);

            // Assert
            var fanZoneAdmins = _unitOfWork.Users.Find(x => x.AdminOfTheaterId == theater.TheaterId &&
                                                       x.ISofAUserRole == ISofAUserRole.FanZoneAdmin);

            Assert.AreEqual(2, fanZoneAdmins.Count());
        }
Ejemplo n.º 2
0
        public void Item_Remove_2_Ok()
        {
            // Arrange
            var theater = new Theater {
                Name = "Arena"
            };

            _unitOfWork.Theaters.Add(theater);
            var item1 = new Item {
                Name = "Test item 1", TheaterId = theater.TheaterId
            };
            var item2 = new Item {
                Name = "Test item 2", TheaterId = theater.TheaterId
            };
            var item3 = new Item {
                Name = "Test item 3", TheaterId = theater.TheaterId
            };

            _unitOfWork.Items.AddRange(new Item[] { item1, item2, item3 });
            _unitOfWork.SaveChanges();

            // Act
            _itemService.RemoveItem(theater.TheaterId, item1.ItemId);
            _itemService.RemoveItem(theater.TheaterId, item2.ItemId);

            // Assert
            Assert.AreEqual(1, _unitOfWork.Items.GetAll().Count());
        }
Ejemplo n.º 3
0
        public void TestCustomUnitOfWork()
        {
            var stopwatch = Stopwatch.StartNew();

            using (var uow = new TestUnitOfWork())
            {
                var users = uow.Users.NewList();
                stopwatch.Stop();
                Console.WriteLine(stopwatch.ElapsedMilliseconds);
                foreach (var user in users)
                {
                    Console.WriteLine($"{user.Id} {user.Login}");
                }
                var dto = new UserDTO
                {
                    Login    = "******",
                    Password = "******"
                };
                dto = uow.Users.Insert(dto);
                uow.SaveChanges();
                var login = dto.Login;
                dto = uow.Users.DTO(d => d.Login == login);
                Assert.IsNotNull(dto);
                Assert.AreNotEqual(dto.Id, 0);
                Console.WriteLine(dto.Id);
                dto.Password = "******";
                uow.Users.Update(dto, dto.Id);
                uow.SaveChanges();
                Assert.AreEqual(dto.Password, uow.Users.DTO(dto.Id).Password);
                uow.Users.Delete(dto.Id);
                uow.SaveChanges();
                Assert.IsNull(uow.Users.DTO(dto.Id));
            }
        }
Ejemplo n.º 4
0
        public void Item_Update_Ok()
        {
            // Arrange
            var theater = new Theater {
                Name = "Arena"
            };

            _unitOfWork.Theaters.Add(theater);
            var item1 = new Item {
                Name = "Test item 1", TheaterId = theater.TheaterId
            };

            _unitOfWork.Items.Add(item1);
            _unitOfWork.SaveChanges();

            // Act
            var updated = _itemService.UpdateItem(theater.TheaterId, item1.ItemId, new Item
            {
                Name = "New name 1"
            });

            var updateGet = _unitOfWork.Items.Get(item1.ItemId);

            Assert.IsNotNull(updated);
            Assert.AreEqual("New name 1", updateGet.Name);
        }
Ejemplo n.º 5
0
        public void AdminsFanZone_Remove_1_Ok()
        {
            // Arrange
            var theater1 = new Theater {
                Name = "Arena"
            };
            var theater2 = new Theater {
                Name = "SNP"
            };

            _unitOfWork.Theaters.Add(theater1);
            _unitOfWork.Theaters.Add(theater2);
            _unitOfWork.SaveChanges();

            var user1 = Utils.CreateFanZoneAdmin(1, theater1.TheaterId);

            _unitOfWork.Users.Add(user1);
            _unitOfWork.Users.Add(Utils.CreateFanZoneAdmin(2, theater1.TheaterId));
            _unitOfWork.Users.Add(Utils.CreateTheaterAdmin(3, theater1.TheaterId));
            _unitOfWork.Users.Add(Utils.CreateFanZoneAdmin(4, theater2.TheaterId));
            _unitOfWork.SaveChanges();

            // Act
            _adminService.RemoveAdmin(theater1.TheaterId, user1.Id);

            // Assert
            var admins = _unitOfWork.Users.Find(x => x.AdminOfTheaterId == theater1.TheaterId);

            Assert.AreEqual(2, admins.Count());
        }
Ejemplo n.º 6
0
        public void UserItems_Add_2_Ok()
        {
            // Arrange
            var theater1 = new Theater {
                Name = "Arena"
            };

            _unitOfWork.Theaters.Add(theater1);
            _unitOfWork.SaveChanges();

            var user1 = Utils.GetTestUser(1);

            _unitOfWork.Users.Add(user1);
            _unitOfWork.SaveChanges();

            // Act
            _userItemService.AddItem(theater1.TheaterId, user1.Id, new UserItem
            {
                ExpirationDate = DateTime.Now.AddHours(2),
            });

            _userItemService.AddItem(theater1.TheaterId, user1.Id, new UserItem
            {
                ExpirationDate = DateTime.Now.AddHours(2),
            });

            // Assert
            var items = _unitOfWork.UserItems
                        .Find(x => x.TheaterId == theater1.TheaterId && x.ISofAUserId == user1.Id);

            Assert.AreEqual(2, items.Count());
        }
        public void UserItems_Approve_2_Ok()
        {
            // Arrange
            var theater1 = new Theater {
                Name = "Arena"
            };
            var theater2 = new Theater {
                Name = "SNP"
            };

            _unitOfWork.Theaters.AddRange(new Theater[] { theater1, theater2 });
            _unitOfWork.SaveChanges();

            var user1 = Utils.GetTestUser(1);
            var user2 = Utils.CreateFanZoneAdmin(2, theater1.TheaterId);

            _unitOfWork.Users.AddRange(new ISofAUser[] { user1, user2 });
            _unitOfWork.SaveChanges();

            var userItem1 = new UserItem
            {
                TheaterId      = theater1.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(2),
                Approved       = null,
                Sold           = false
            };

            var userItem2 = new UserItem
            {
                TheaterId      = theater1.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(-2),
                Approved       = null,
                Sold           = false
            };

            _unitOfWork.UserItems.AddRange(new UserItem[] { userItem1, userItem2 });
            _unitOfWork.SaveChanges();

            // Act
            var approved1 = _userItemService.ApproveItem(theater1.TheaterId, userItem1.UserItemId);
            var approved2 = _userItemService.ApproveItem(theater1.TheaterId, userItem2.UserItemId);

            // Assert
            var approved = _unitOfWork.UserItems
                           .Find(x => x.TheaterId == theater1.TheaterId && x.Approved == true);
            var notApproved = _unitOfWork.UserItems.Find(x => x.TheaterId == theater1.TheaterId && x.Approved == null);

            Assert.AreEqual(2, approved.Count());
            Assert.AreEqual(0, notApproved.Count());
        }
Ejemplo n.º 8
0
        public void MultipleChangesInUnitOfWorkAreSavedOnce()
        {
            TestAggregateRoot aggregateRoot1 = new TestAggregateRoot(Guid.NewGuid());

            aggregateRoot1.ApplyEvent(domainEvent);

            TestDomainEvent domainEvent2 = new TestDomainEvent(Guid.NewGuid());

            unitOfWorkEventHandlerResolver.ResolveEventHandlers <IUnitOfWorkDomainEventHandler <TestDomainEvent, TestUnitOfWork> >().Returns(unitOfWorkDomainEventHandlers);

            TestAggregateRoot aggregateRoot2 = new TestAggregateRoot(Guid.NewGuid());

            aggregateRoot2.ApplyEvent(domainEvent2);

            sut.ApplyChanges(new List <TestAggregateRoot> {
                aggregateRoot1, aggregateRoot2
            });

            Received.InOrder(() =>
            {
                unitOfWorkDomainEventHandler1.Execute(domainEvent, unitOfWork);
                unitOfWorkDomainEventHandler1.Execute(domainEvent2, unitOfWork);
                unitOfWork.SaveChanges();
            });
        }
Ejemplo n.º 9
0
        public void Theater_Update_Ok()
        {
            // Arrange
            var theater = new Theater
            {
                Name      = "Arena cineplex",
                Latitude  = 15,
                Longitude = 15,
                Type      = TheaterType.Cinema
            };

            _unitOfWork.Theaters.Add(theater);
            _unitOfWork.SaveChanges();

            // Act
            var updateAct = new Theater
            {
                Name      = "SNP",
                Latitude  = 30,
                Longitude = 30,
                Type      = TheaterType.Play
            };

            var updated = _theaterService.Update(theater.TheaterId, updateAct);

            var afterUpdateCinemas = _theaterService.GetAllCinemas();
            var afterUpdatePlays   = _theaterService.GetAllPlayTheaters();

            // Assert
            Assert.AreEqual(updateAct.Name, updated.Name);
            Assert.AreEqual(updateAct.Latitude, updated.Latitude);
            Assert.AreEqual(updateAct.Longitude, updated.Longitude);
            Assert.AreEqual(0, afterUpdateCinemas.Count());
            Assert.AreEqual(1, afterUpdatePlays.Count());
        }
Ejemplo n.º 10
0
        public void ItemService_Add_2_Ok()
        {
            var theater = new Theater {
                Name = "Arena", Type = TheaterType.Cinema
            };
            var theater2 = new Theater {
                Name = "SNP", Type = TheaterType.Play
            };

            _unitOfWork.Theaters.Add(theater);
            _unitOfWork.Theaters.Add(theater2);
            _unitOfWork.SaveChanges();

            _itemService.AddItem(theater.TheaterId, new Item {
                Name = "Arena item"
            });
            _itemService.AddItem(theater.TheaterId, new Item {
                Name = "Arena item"
            });
            _itemService.AddItem(theater2.TheaterId, new Item {
                Name = "SNP item"
            });

            var theaterItems  = _itemService.GetItemsForTheater(theater.TheaterId);
            var theater2Items = _itemService.GetItemsForTheater(theater2.TheaterId);

            Assert.AreEqual(2, theaterItems.Count());
            Assert.AreEqual(1, theater2Items.Count());
        }
        public void ResolvedEventHandlersAreExecutedInCorrectOrder()
        {
            TestAggregateRoot aggregateRoot = new TestAggregateRoot(Guid.NewGuid());

            aggregateRoot.ApplyEvent(domainEvent1);

            TestAggregateRoot2 aggregateRoot2 = new TestAggregateRoot2(Guid.NewGuid());

            aggregateRoot.ApplyEvent(domainEvent2);

            sut.ApplyChanges(aggregateRoot, aggregateRoot2);

            Received.InOrder(() =>
            {
                unitOfWorkDomainEventHandler1.Execute(domainEvent1, unitOfWork);
                unitOfWorkDomainEventHandler2.Execute(domainEvent1, unitOfWork);
                unitOfWorkDomainEventHandler1.Execute(domainEvent2, unitOfWork);
                unitOfWorkDomainEventHandler2.Execute(domainEvent2, unitOfWork);
                unitOfWork.SaveChanges();
                domainEventHandler3.Execute(domainEvent1);
                domainEventHandler4.Execute(domainEvent1);
                domainEventHandler3.Execute(domainEvent2);
                domainEventHandler4.Execute(domainEvent2);
            });
        }
Ejemplo n.º 12
0
        public void Theater_Get_All_Cinemas_2()
        {
            // Arrange
            _unitOfWork.Theaters.Add(new Theater {
                Name = "Arena Cineplex", Type = TheaterType.Cinema
            });
            _unitOfWork.Theaters.Add(new Theater {
                Name = "Sinestar", Type = TheaterType.Cinema
            });
            _unitOfWork.SaveChanges();

            // Act
            var theaters = _theaterService.GetAllCinemas();

            // Assert
            Assert.AreEqual(2, theaters.Count());
        }
Ejemplo n.º 13
0
        public void Items_Get_All_2()
        {
            var theater = new Theater {
                Name = "Arena"
            };

            _unitOfWork.Theaters.Add(theater);
            _unitOfWork.Items.Add(new Item {
                Name = "Test item", TheaterId = theater.TheaterId
            });
            _unitOfWork.Items.Add(new Item {
                Name = "Test2 item", TheaterId = theater.TheaterId
            });
            _unitOfWork.SaveChanges();

            var items = _itemService.GetItemsForTheater(theater.TheaterId);

            Assert.AreEqual(2, items.Count());
        }
        public void Theater_Remove_1()
        {
            // Arrange
            var newTheater = new Theater {
                Name = "Remove"
            };

            _unitOfWork.Theaters.Add(newTheater);
            _unitOfWork.SaveChanges();

            // Act
            var beforeDelete = _theaterService.GetAll();

            _theaterService.Remove(newTheater.TheaterId);
            var afterDelete = _theaterService.GetAll();

            // Assert
            Assert.AreEqual(1, beforeDelete.Count());
            Assert.AreEqual(0, afterDelete.Count());
        }
Ejemplo n.º 15
0
        public void AdminsFanZone_Get_All_2()
        {
            // Arrange
            var theater1 = new Theater {
                Name = "Arena"
            };
            var theater2 = new Theater {
                Name = "SNP"
            };

            _unitOfWork.Theaters.Add(theater1);
            _unitOfWork.Theaters.Add(theater2);
            _unitOfWork.SaveChanges();

            _unitOfWork.Users.Add(Utils.CreateFanZoneAdmin(1, theater1.TheaterId));
            _unitOfWork.Users.Add(Utils.CreateFanZoneAdmin(2, theater1.TheaterId));
            _unitOfWork.Users.Add(Utils.CreateTheaterAdmin(3, theater1.TheaterId));
            _unitOfWork.Users.Add(Utils.CreateFanZoneAdmin(4, theater2.TheaterId));
            _unitOfWork.SaveChanges();

            // Act
            var fanZoneAdmins1 = _adminService.GetFanZoneAdmins(theater1.TheaterId);
            var fanZoneAdmins2 = _adminService.GetFanZoneAdmins(theater2.TheaterId);

            // Assert
            Assert.AreEqual(2, fanZoneAdmins1.Count());
            Assert.AreEqual(1, fanZoneAdmins2.Count());
        }
Ejemplo n.º 16
0
        public void Items_Buy_2_Ok()
        {
            // Arrange
            var user = Utils.GetTestUser(1);

            _unitOfWork.Users.Add(user);

            var theater = new Theater {
                Name = "Arena"
            };

            _unitOfWork.Theaters.Add(theater);
            var item1 = new Item {
                Name = "Test item 1", TheaterId = theater.TheaterId
            };
            var item2 = new Item {
                Name = "Test item 2", TheaterId = theater.TheaterId
            };
            var item3 = new Item {
                Name = "Test item 3", TheaterId = theater.TheaterId
            };

            _unitOfWork.Items.AddRange(new Item[] { item1, item2, item3 });
            _unitOfWork.SaveChanges();

            // Act
            bool success = _itemService.BuyItems(new Item[] { item1, item2 }, user.Id);

            Assert.IsTrue(success);

            var afterBuy = _itemService.GetItemsForTheater(theater.TheaterId);

            Assert.AreEqual(1, afterBuy.Count());

            var bought = _itemService.GetBoughtItemsForTheater(theater.TheaterId);

            Assert.AreEqual(2, bought.Count());
        }
        public void UserItems_Remove_1_Ok()
        {
            // Arrange
            var theater1 = new Theater {
                Name = "Arena"
            };
            var theater2 = new Theater {
                Name = "SNP"
            };

            _unitOfWork.Theaters.AddRange(new Theater[] { theater1, theater2 });
            _unitOfWork.SaveChanges();

            var user1 = Utils.GetTestUser(1);

            _unitOfWork.Users.Add(user1);
            _unitOfWork.SaveChanges();

            var userItem1 = new UserItem
            {
                TheaterId      = theater1.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(2),
                Approved       = null,
                Sold           = false
            };

            var userItem2 = new UserItem
            {
                TheaterId      = theater1.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(-2),
                Approved       = null,
                Sold           = false
            };

            _unitOfWork.UserItems.AddRange(new UserItem[] { userItem1, userItem2 });
            _unitOfWork.SaveChanges();

            // Act
            _userItemService.RemoveItem(theater1.TheaterId, userItem1.UserItemId);

            // Assert
            var foundItem = _unitOfWork.UserItems.Find(x => x.UserItemId == userItem1.UserItemId).FirstOrDefault();

            Assert.IsNull(foundItem);
        }
Ejemplo n.º 18
0
        public void UserItems_Get_All_1_Expired()
        {
            // Arrange
            var theater1 = new Theater {
                Name = "Arena"
            };
            var theater2 = new Theater {
                Name = "SNP"
            };

            _unitOfWork.Theaters.AddRange(new Theater[] { theater1, theater2 });
            _unitOfWork.SaveChanges();

            var user1 = Utils.GetTestUser(1);

            _unitOfWork.Users.Add(user1);
            _unitOfWork.SaveChanges();

            var userItem1 = new UserItem
            {
                TheaterId      = theater1.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(2),
                Approved       = true,
                Sold           = false
            };

            var userItem2 = new UserItem
            {
                TheaterId      = theater1.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(-2),
                Approved       = true,
                Sold           = false
            };

            _unitOfWork.UserItems.AddRange(new UserItem[] { userItem1, userItem2 });
            _unitOfWork.SaveChanges();

            // Act
            var userItems = _userItemService.GetItemsForTheater(theater1.TheaterId);

            // Assert
            Assert.AreEqual(1, userItems.Count());
        }
Ejemplo n.º 19
0
        public async Task UserItem_Sell_Item_OkAsync()
        {
            // Arrange
            var theater = new Theater {
                Name = "Arena"
            };

            _unitOfWork.Theaters.Add(theater);
            _unitOfWork.SaveChanges();

            var user1 = Utils.GetTestUser(1);
            var user2 = Utils.GetTestUser(2);
            var user3 = Utils.GetTestUser(3);

            _unitOfWork.Users.AddRange(new[] { user1, user2, user3 });
            _unitOfWork.SaveChanges();

            var userItem = new UserItem
            {
                TheaterId      = theater.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(2),
                Approved       = true,
                Sold           = false
            };

            _unitOfWork.UserItems.Add(userItem);
            _unitOfWork.SaveChanges();

            var bid1 = new Bid {
                Bidder = user2, UserItem = userItem, BidDate = DateTime.Now, BidAmount = 50
            };
            var bid2 = new Bid {
                Bidder = user3, UserItem = userItem, BidDate = DateTime.Now, BidAmount = 60
            };

            _unitOfWork.Bids.AddRange(new[] { bid1, bid2 });
            _unitOfWork.SaveChanges();

            // Act
            var soldItem = await _bidService.SellItemAsync(user1.Id, userItem.UserItemId, bid2.BidderId);

            // Assert
            var foundItem = _unitOfWork.UserItems.Get(userItem.UserItemId);

            Assert.IsNotNull(soldItem);
            Assert.IsTrue(foundItem.Sold);
        }
Ejemplo n.º 20
0
        public void Bids_Add_2_Ok()
        {
            // Arrange
            var theater = new Theater {
                Name = "Arena"
            };

            _unitOfWork.Theaters.Add(theater);
            _unitOfWork.SaveChanges();

            var user1 = Utils.GetTestUser(1);
            var user2 = Utils.GetTestUser(2);
            var user3 = Utils.GetTestUser(3);

            _unitOfWork.Users.AddRange(new[] { user1, user2, user3 });
            _unitOfWork.SaveChanges();

            var userItem = new UserItem {
                TheaterId      = theater.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(2),
                Approved       = true,
                Sold           = false
            };

            _unitOfWork.UserItems.Add(userItem);
            _unitOfWork.SaveChanges();

            // Act
            _bidService.AddBid(userItem.UserItemId, user2.Id, new Bid {
                BidAmount = 50
            });
            _bidService.AddBid(userItem.UserItemId, user3.Id, new Bid {
                BidAmount = 60
            });

            // Assert
            var bids = _unitOfWork.Bids.Find(x => x.UserItemId == userItem.UserItemId);

            Assert.AreEqual(2, bids.Count());
        }
Ejemplo n.º 21
0
        public void Bids_Get__All_3()
        {
            // Arrange
            var theater = new Theater {
                Name = "Arena"
            };

            _unitOfWork.Theaters.Add(theater);
            _unitOfWork.SaveChanges();

            var user1 = Utils.GetTestUser(1);
            var user2 = Utils.GetTestUser(2);
            var user3 = Utils.GetTestUser(3);
            var user4 = Utils.GetTestUser(4);

            _unitOfWork.Users.AddRange(new[] { user1, user2, user3, user4 });
            _unitOfWork.SaveChanges();

            var userItem1 = new UserItem
            {
                TheaterId      = theater.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(2),
                Approved       = true,
                Sold           = false
            };
            var userItem2 = new UserItem
            {
                TheaterId      = theater.TheaterId,
                ISofAUserId    = user1.Id,
                ExpirationDate = DateTime.Now.AddHours(2),
                Approved       = true,
                Sold           = false
            };

            _unitOfWork.UserItems.AddRange(new[] { userItem1, userItem2 });
            _unitOfWork.SaveChanges();

            var bid1 = new Bid {
                Bidder = user2, UserItem = userItem1, BidDate = DateTime.Now, BidAmount = 50
            };
            var bid2 = new Bid {
                Bidder = user3, UserItem = userItem1, BidDate = DateTime.Now, BidAmount = 60
            };
            var bid3 = new Bid {
                Bidder = user4, UserItem = userItem1, BidDate = DateTime.Now, BidAmount = 70
            };
            var bid4 = new Bid {
                Bidder = user1, UserItem = userItem2, BidDate = DateTime.Now, BidAmount = 50
            };

            _unitOfWork.Bids.AddRange(new[] { bid1, bid2, bid3, bid4 });
            _unitOfWork.SaveChanges();

            // Act
            var bids1 = _bidService.GetAll(userItem1.UserItemId);
            var bids2 = _bidService.GetAll(userItem2.UserItemId);
            var bids3 = _bidService.GetAll(Guid.NewGuid());

            // Arrange
            Assert.AreEqual(1, bids2.Count());
            Assert.AreEqual(3, bids1.Count());
            Assert.AreEqual(0, bids3.Count());
        }