public void Add_Should_Work_As_Expected()
        {
            //Arrange
            TestEntity entity = new TestEntity();

            //Act
            _repository.Add(entity);
            _testDbContext.SaveChanges();

            //Assert
            Assert.NotNull(_testDbContext.TestEntities.FirstOrDefault());
        }
Beispiel #2
0
        public JsonResult Upload(HttpPostedFileBase file)
        {
            if (_repository.GetAll().Any(x => x.FileName == file.FileName && x.ContentLength == file.ContentLength))
            {
                return(Json(_repository.GetAll().Count()));
            }

            using (var b = new BinaryReader(file.InputStream))
            {
                var binData = b.ReadBytes(file.ContentLength);

                _repository.Add(new Document
                {
                    ContentLength = binData.Count(),
                    ContentType   = file.ContentType,
                    CreatedTime   = DateTime.Now,
                    Data          = binData,
                    Description   = String.Empty,
                    FileName      = file.FileName,
                    Owner         = _accountRepository.FindByName(User.Identity.Name)
                });
            }

            return(Json(_repository.GetAll().Count()));
        }
        public IHttpActionResult PostAddUser(User user)
        {
            EmailService emailservice = new ShoppingCore.Service.EmailService();

            user.Password = new PasswordService().GeneratePassword(10);
            emailservice.SendRegisterMail("Shopping Cart User Registration", user.Email, user.Name, user.Password, "http://localhost:4200/Login");
            return(Ok(_efr.Add(user)));
        }
Beispiel #4
0
        public void TestCourseAddWithoutRequiredFK()
        {
            var courses = new EntityFrameworkRepository <Course>(context);

            var newCourse = new Course {
                Name = "Testowe zajecia"
            };

            courses.Add(newCourse);
            courses.SaveChanges();
        }
Beispiel #5
0
        public void TestAdd_ShouldCallDbContextSetAdded()
        {
            // Arrange
            var mockedDbContext = new Mock <ILogsDbContext>();

            var repository = new EntityFrameworkRepository <FakeGenericRepositoryType>(mockedDbContext.Object);

            var entity = new Mock <FakeGenericRepositoryType>();

            // Act
            repository.Add(entity.Object);

            // Assert
            mockedDbContext.Verify(c => c.SetAdded(entity.Object), Times.Once);
        }
Beispiel #6
0
        public void TestCourseAddWithRequiredFK()
        {
            var courses = new EntityFrameworkRepository <Course>(context);
            var owner   = users.GetById(1);

            var newCourse = new Course {
                Name = "Testowe zajecia", Owner = owner
            };

            courses.Add(newCourse);
            courses.SaveChanges();

            var addedCourse = courses.GetByOwner(owner).Where(t => t.Name == newCourse.Name).First();

            Assert.IsNotNull(addedCourse);
            Assert.AreEqual(newCourse.Owner.Id, addedCourse.Owner.Id);
        }
        public void CreateCustomerTest()
        {
            IRepository <Customer> customersRepository = new EntityFrameworkRepository <Customer>("InventoryContext");
            Customer customer = new Customer()
            {
                FName    = "Dave",
                LName    = "Richardson",
                Address1 = "605 Sharview Cir",
                Address2 = "#1735",
                State    = "NC",
                Country  = "USA",
                Zipcode  = "28217",
                Phone    = "1234567890",
                Email    = "*****@*****.**"
            };
            var response = customersRepository.Add(customer);

            customersRepository.SaveChanges();
        }
Beispiel #8
0
        public void Test_DoubleTest_InsertToDatabase()
        {
            var configuration = new EntitySetupConfiguration();

            // const string connectionString = "Data Source=(local); Database=easyERP_test; User ID=sa; Password=; MultipleActiveResultSets=True";
            // EntityFrameworkDbContext dbContext = new EntityFrameworkDbContext(connectionString, configuration);
            // DbConnection dbConnection = new SqlConnection();
            var dbContext = new EntityFrameworkDbContext("easyERP_test");

            IUnitOfWork unitOfWork     = new EntityFrameworkUnitOfWork(dbContext);
            var         testRepository = new EntityFrameworkRepository <TestDoubles>(dbContext, unitOfWork);
            var         testModel      = new TestDoubles
            {
                Name = "test description"
            };

            testRepository.Add(testModel);
            unitOfWork.Commit();
        }
 public IHttpActionResult PostAddProduct(Product product)
 {
     return(Ok(_efr.Add(product)));
 }
Beispiel #10
0
 public IHttpActionResult PostAddWishList(WishList wishlist)
 {
     return(Ok(_efr.Add(wishlist)));
 }
Beispiel #11
0
 public IHttpActionResult PostAddProductCategory(ProductCategory productCategory)
 {
     return(Ok(_efr.Add(productCategory)));
 }
Beispiel #12
0
 public IHttpActionResult PostItem(LineItem item)
 {
     erf.Add(item);
     return(Ok("LineItem Added..."));
 }
Beispiel #13
0
 public IHttpActionResult PostAddProduct(Address address)
 {
     return(Ok(_efr.Add(address)));
 }
Beispiel #14
0
 public IHttpActionResult PostUser(User user)
 {
     erf.Add(user);
     return(Ok("Data Added"));
 }
 public IHttpActionResult PostOrder(Order order)
 {
     erf.Add(order);
     return(Ok("Order Added..."));
 }
Beispiel #16
0
 public IHttpActionResult PostAddLineItem(LineItem lineitem)
 {
     return(Ok(_efr.Add(lineitem)));
 }
        public async Task GivenRepository_WhenFullCRUDFlowIsRun_ThenSucceed()
        {
            var builder = new DbContextOptionsBuilder <UsersDbContext>();

            builder.UseNpgsql(ConnectionString,
                              x => x.MigrationsHistoryTable(
                                  HistoryRepository.DefaultTableName,
                                  SchemaName));

            User user;

            await using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext, new NulloAggregateEventsPublisher());

                await dbContext.Database.MigrateAsync();

                user = new User {
                    Id = 0, UserName = "******", FullName = null
                };

                //1. Add
                var result = await repository.Add(user);

                await repository.SaveChanges();

                result.Should().NotBe(null);
                result.Id.Should().BeGreaterThan(0);
                result.UserName.Should().Be("*****@*****.**");
                result.FullName.Should().BeNull();
            }
            //2. GetById

            await using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext, new NulloAggregateEventsPublisher());

                var recordFromDb = await repository.FindById(user.Id);

                recordFromDb.Should().BeEquivalentTo(user);
            }

            //3. Update
            await using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext, new NulloAggregateEventsPublisher());

                var userToUpdate = new User {
                    Id = user.Id, UserName = "******", FullName = "Tom Smith"
                };

                repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext, new NulloAggregateEventsPublisher());
                var result = await repository.Update(userToUpdate);

                await repository.SaveChanges();

                result.Should().NotBe(null);
                result.Id.Should().Be(user.Id);
                result.UserName.Should().Be("*****@*****.**");
                result.FullName.Should().Be("Tom Smith");

                var recordFromDb = await repository.FindById(userToUpdate.Id);

                recordFromDb.Should().BeEquivalentTo(result);
            }

            //4. Remove
            await using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext, new NulloAggregateEventsPublisher());

                var result = await repository.DeleteById(user.Id);

                await repository.SaveChanges();

                result.Should().BeTrue();

                var recordFromDb = await repository.FindById(user.Id);

                recordFromDb.Should().Be(null);
            }
            //5. Add Range
            await using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext, new NulloAggregateEventsPublisher());

                var results = (await repository.AddAll(
 public IHttpActionResult PostWishlist(Wishlist wishlist)
 {
     erf.Add(wishlist);
     return(Ok("wishlist Added..."));
 }
 public IHttpActionResult PostProduct(Product product)
 {
     erf.Add(product);
     return(Ok("Product Added"));
 }
Beispiel #20
0
 public IHttpActionResult PostAddress(Address address)
 {
     erf.Add(address);
     return(Ok("Address Added"));
 }
Beispiel #21
0
        public void GivenRepository_WhenFullCRUDFlowIsRun_ThenSucceed()
        {
            var builder = new DbContextOptionsBuilder <UsersDbContext>();

            builder.UseNpgsql(ConnectionString,
                              x => x.MigrationsHistoryTable(
                                  HistoryRepository.DefaultTableName,
                                  SchemaName));

            User user = null;

            using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext);

                dbContext.Database.Migrate();

                user = new User {
                    Id = 0, UserName = "******", FullName = null
                };

                //1. Add
                var result = repository.Add(user);
                repository.SaveChanges();

                result.Should().NotBe(null);
                result.Id.Should().BeGreaterThan(0);
                result.UserName.Should().Be("*****@*****.**");
                result.FullName.Should().BeNull();
            }
            //2. GetById

            using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext);

                var recordFromDb = repository.FindById(user.Id);

                recordFromDb.Should().BeEquivalentTo(user);
            }

            //3. Update
            using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext);

                var userToUpdate = new User {
                    Id = user.Id, UserName = "******", FullName = "Tom Smith"
                };

                repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext);
                var result = repository.Update(userToUpdate);
                repository.SaveChanges();

                result.Should().NotBe(null);
                result.Id.Should().Be(user.Id);
                result.UserName.Should().Be("*****@*****.**");
                result.FullName.Should().Be("Tom Smith");

                var recordFromDb = repository.FindById(userToUpdate.Id);

                recordFromDb.Should().BeEquivalentTo(result);
            }



            //4. Remove
            using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext);

                var result = repository.DeleteById(user.Id);
                repository.SaveChanges();

                result.Should().BeTrue();

                var recordFromDb = repository.FindById(user.Id);

                recordFromDb.Should().Be(null);
            }
            //5. Add Range
            using (var dbContext = new UsersDbContext(builder.Options))
            {
                var repository = new EntityFrameworkRepository <UsersDbContext, User>(dbContext);

                var results = repository.AddAll(
                    new User {
                    UserName = "******"
                },
                    new User {
                    UserName = "******"
                },
                    new User {
                    UserName = "******"
                }
                    )?.ToList();
                repository.SaveChanges();

                results.Should().NotBeNull();
                results.Should().HaveCount(3);

                results[0].Id.Should().BeGreaterThan(0);
                results[0].UserName.Should().Be("*****@*****.**");
                results[0].FullName.Should().BeNull();

                results[1].Id.Should().BeGreaterThan(0);
                results[1].UserName.Should().Be("*****@*****.**");
                results[1].FullName.Should().BeNull();

                results[2].Id.Should().BeGreaterThan(0);
                results[2].UserName.Should().Be("*****@*****.**");
                results[2].FullName.Should().BeNull();

                //6. Query

                var queryResults = repository.Query().ToList();

                queryResults.Should().Contain(x => results.Select(u => u.Id).Contains(x.Id));

                queryResults = repository.Query().ToList().Where(x => x.UserName == results[1].UserName).ToList();

                queryResults.Should().HaveCountGreaterOrEqualTo(1);
                queryResults.First(x => x.Id == results[1].Id).Should().BeEquivalentTo(results[1]);
            }
        }
 public IHttpActionResult PostAddProduct(Order order)
 {
     return(Ok(_efr.Add(order)));
 }