Esempio n. 1
0
        public void CreateOwner_SpecifiedId_ThrowsNotSupportedException()
        {
            Mock <IOwnerRepository> ownerRepository = new Mock <IOwnerRepository>();
            OwnerService            ownerService    = new OwnerService(ownerRepository.Object);
            Owner owner = new Owner()
            {
                Id = 1
            };

            Action actual = () => ownerService.Create(owner);

            Assert.Throws <NotSupportedException>(actual);
        }
Esempio n. 2
0
        public void CreateOwner_NullFirstName_ThrowsInvalidDataException()
        {
            Mock <IOwnerRepository> ownerRepository = new Mock <IOwnerRepository>();
            OwnerService            ownerService    = new OwnerService(ownerRepository.Object);
            Owner owner = new Owner()
            {
                LastName = "lastName", Address = "address", PhoneNumber = "phoneNumber", Email = "email"
            };

            Action actual = () => ownerService.Create(owner);

            Assert.Throws <InvalidDataException>(actual);
        }
Esempio n. 3
0
        public async void GetAllOwners_Sorts_Results_By_Name()
        {
            // Arrange
            var mockOwnerRepository   = new Mock <IOwnerRepository>();
            var mockRepositoryWrapper = new Mock <IRepositoryWrapper>();

            var dylan = new Owner()
            {
                Id      = Guid.NewGuid(),
                Name    = "Dylan",
                Address = "my address"
            };

            var crystal = new Owner()
            {
                Id      = Guid.NewGuid(),
                Name    = "Crystal",
                Address = "my address"
            };

            var ownersToReturn = new List <Owner>()
            {
                dylan,
                crystal
            }.AsQueryable();

            mockOwnerRepository.Setup(m => m.FindAll()).Returns(ownersToReturn);

            var mockLogger = NullLogger <OwnerService> .Instance;

            var mockMapper = new Mock <IMapper>();

            var ownersAsDtos = ownersToReturn.Select(o => new OwnerDto()
            {
                Id      = o.Id,
                Name    = o.Name,
                Address = o.Address
            });

            mockMapper.Setup(m => m.Map <IEnumerable <OwnerDto> >(
                                 It.Is <IEnumerable <Owner> >(
                                     o => o.ToList()[0] == crystal && o.ToList()[1] == dylan))
                             ).Returns(ownersAsDtos);

            // Act
            var ownerService = new OwnerService(mockRepositoryWrapper.Object, mockLogger, mockMapper.Object);
            var result       = await ownerService.GetAllOwnersAsync();

            // Assert
            Assert.Equal(2, result.Count());
        }
        public static bool CreateUpdateOwner(ManageOwnerViewModel model)
        {
            ManageOwnerEntity entity = new ManageOwnerEntity();

            entity.OwnerAddress     = new OwnerAddressEntity();
            entity.OwnerBankDetails = new OwnerBankDetailEntity();

            entity.OwnerId      = model.OwnerId;
            entity.OwnerName    = model.OwnerName;
            entity.ContactNo    = model.ContactNumber;
            entity.GSTNo        = model.GSTNumber;
            entity.Juridication = model.Juridication;
            entity.BusinessType = model.BusiniessType;

            if (model.OwnerAddresses != null)
            {
                foreach (var item in model.OwnerAddresses.AddressList)
                {
                    entity.OwnerAddress.AddressList.Add(new OwnerAddressEntity()
                    {
                        Street1   = item.Street1,
                        City      = item.City,
                        Id        = item.Id,
                        PostCode  = item.PostCode,
                        StateId   = item.StateId,
                        Street2   = item.Street2,
                        IsCreated = item.IsCreated,
                        IsUpdated = item.IsUpdated
                    });
                }
            }

            if (model.OwnerBank != null)
            {
                foreach (var item in model.OwnerBank.OwnerBankList)
                {
                    entity.OwnerBankDetails.OwnerBankList.Add(new OwnerBankDetailEntity()
                    {
                        AccountNumber = item.AccountNumber,
                        BankName      = item.BankName,
                        Branch        = item.Branch,
                        Id            = item.Id,
                        IFSC          = item.IFSC,
                        IsCreated     = item.IsCreated,
                        IsUpdated     = item.IsUpdated
                    });
                }
            }

            return(OwnerService.CreateUpdateOwner(entity));
        }
Esempio n. 5
0
        public void CreateOwnerEmptyLastNameThrowsException()
        {
            var ownerRepo = new Mock <IOwnerRepository>();
            var petRepo   = new Mock <IPetRepository>();
            var service   = new OwnerService(ownerRepo.Object, petRepo.Object);

            var owner = new Owner {
                FirstName = "Owner1"
            };

            var ex = Assert.Throws <InvalidDataException>(() => service.CreateOwner(owner));

            Assert.Equal("Owner needs a LastName to be created", ex.Message);
        }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseSwagger();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            using (var scope = app.ApplicationServices.CreateScope())
            {
                var repo  = scope.ServiceProvider.GetRequiredService <IAvatarRepository>();
                var orepo = scope.ServiceProvider.GetRequiredService <IOwnerRepository>();
                var trepo = scope.ServiceProvider.GetRequiredService <ITypeRepository>();

                /* repo.Create(new Avatar { Name = "Chili", AvatarType = "Magician", Color = "Pink" });
                 * repo.Create(new Avatar { Name = "Bunsy", AvatarType = "Healer", Color = "Black" });*/

                IAvatarRepository aRepo  = new AvatarRepo();
                IOwnerRepository  owRepo = new OwnerRepo();
                ITypeRepository   tyrepo = new TypeRepo();


                DBInit.InitData(); // Mock data
                IAvatarService aService  = new AvatarService(aRepo);
                IOwnerService  owService = new OwnerService(owRepo);
                ITypeService   tService  = new TypeService(tyrepo);



                app.UseSwaggerUI(c =>
                {
                    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
                    // c.RoutePrefix = string.Empty;
                });

                app.UseHttpsRedirection();
                app.UseRouting();

                app.UseCors("CustomerAppAllowSpecificOrigins");


                app.UseAuthorization();

                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllers();
                });
            }
        }
        public static List <SelectListItem> GetStateDropDown()
        {
            var Data = OwnerService.GetStateDD().Select(m => new SelectListItem()
            {
                Text  = m.StateName,
                Value = m.Id.ToString()
            }).ToList();

            Data.Insert(0, new SelectListItem {
                Value = "", Text = "Please Select State"
            });

            return(Data);
        }
        public static ManageOwnerViewModel GetOwnerById(int OwnerId)
        {
            ManageOwnerViewModel model = new ManageOwnerViewModel();

            model.OwnerAddresses         = new OwnerAddress();
            model.OwnerBank              = new OwnerBankDetail();
            model.OwnerAddresses.StateDD = clsOwnerManangement.GetStateDropDown();
            var Data = OwnerService.GetOwnerById(OwnerId);

            if (Data != null)
            {
                model.OwnerId       = Data.OwnerId;
                model.OwnerName     = Data.OwnerName;
                model.ContactNumber = Data.ContactNo;
                model.GSTNumber     = Data.GSTNo;
                model.Juridication  = Data.Juridication;
                model.BusiniessType = Data.BusinessType;

                foreach (var item in Data.OwnerAddress.AddressList)
                {
                    model.OwnerAddresses.AddressList.Add(new OwnerAddress()
                    {
                        Id         = item.Id,
                        Street1    = item.Street1,
                        Street2    = item.Street2,
                        City       = item.City,
                        PostCode   = item.PostCode,
                        StateId    = item.StateId,
                        StateDD    = clsOwnerManangement.GetStateDropDown(),
                        StateValue = clsOwnerManangement.GetStateDropDown().Where(x => x.Value == item.StateId.ToString()).Select(x => x.Text).FirstOrDefault()
                    });
                }

                foreach (var item in Data.OwnerBankDetails.OwnerBankList)
                {
                    model.OwnerBank.OwnerBankList.Add(new OwnerBankDetail()
                    {
                        Id            = item.Id,
                        BankName      = item.BankName,
                        Branch        = item.Branch,
                        AccountNumber = item.AccountNumber,
                        IFSC          = item.IFSC
                    });
                }
            }


            return(model);
        }
Esempio n. 9
0
        public async Task Invoke(HttpContext context)
        {
            _ownereService = (OwnerService)context.RequestServices.GetService(typeof(OwnerService));
            String ownerId = context.Request.Headers["Owner"];

            if (ownerId == null)
            {
                ownerId = context.Request.Cookies["owner"];
            }
            if (ownerId != null)
            {
                _ownereService.OwnerId = Convert.ToInt64(ownerId);
            }
            await _next.Invoke(context);
        }
Esempio n. 10
0
            public async Task WhenEmptyResponse_GivesEmptyResult()
            {
                // Arrange
                var   requestUri       = string.Empty;
                Owner expectedResponse = null;
                var   mockHandler      = new Mock <IHttpClientHandler>();

                mockHandler.SetupGetStringAsync(requestUri, "", HttpStatusCode.OK);
                var ownerService = new OwnerService(mockHandler.Object);
                // Act
                var result = await ownerService.GetOwnerFromUrlAsync(requestUri, CancellationToken.None);

                // Assert
                Assert.AreEqual(expectedResponse, result);
            }
        static void Main(string[] args)
        {
            OwnerService   ownerService   = new OwnerService(new OwnerRepository());
            AccountService accountService = new AccountService(new AccountRepository(), ownerService, new AccountNumberGenerator());

            string baseNumberAccount1 = accountService.CreateAccount(new BaseAccountFactory(), "Kb147147", "UserFirstName", "UserLastName", "email", 10);
            string baseNumberAccount2 = accountService.CreateAccount(new BaseAccountFactory(), "KB147147", 7);

            // accountService.CloseAccount(baseNumberAccount1);

            accountService.PutMoney(baseNumberAccount1, 12);
            accountService.PutMoney(baseNumberAccount2, 10);
            //  accountService.TakeMoney(baseNumberAccount2, 4);
            //    accountService.Transfer(baseNumberAccount1, baseNumberAccount2, 3);
        }
Esempio n. 12
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            //This is new

            using (var scope = app.ApplicationServices.CreateScope())
            {
                var repo   = scope.ServiceProvider.GetRequiredService <IAvatarRepository>();
                var atrepo = scope.ServiceProvider.GetRequiredService <IAvatarTypeRepository>();
                var owrepo = scope.ServiceProvider.GetRequiredService <IOwnerRepository>();
                //repo.Create(new Avatar { Name = "Bunsy", Type ="Bunny", Color ="Blue"});
                //repo.Create(new Avatar { Name = "Chili", Type = "Magician", Color = "Pink" });

                IAvatarRepository     avatarRepository     = new AvatarRepo();
                IAvatarTypeRepository avatarTypeRepository = new AvatarTypeRepo();
                IOwnerRepository      ownerRepository      = new OwnerRepo();

                //new DBinitializer  = new DBinitializer();
                //d.InitData();

                DBinitializer.InitData();
                IAvatarService     avatarService     = new AvatarService(avatarRepository);
                IAvatarTypeService avatarTypeService = new AvatarTypeService(avatarTypeRepository);
                IOwnerService      ownerService      = new OwnerService(ownerRepository);



                //YOU DID GITHUB WIHT TERMINAL !!!


                // app.UseWelcomePage();

                app.UseHttpsRedirection();

                app.UseRouting();

                app.UseAuthorization();

                app.UseEndpoints(endpoints =>
                {
                    endpoints.MapControllers();
                });
            }
        }
        public ResponseResult <Cookie> Reg([FromBody] Owner owner)
        {
            ResponseResult <Cookie> result = new ResponseResult <Cookie>();

            try
            {
                OwnerService ownerService = new OwnerService();
                result.Result = ownerService.AddOwner(owner);
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Message   = e.Message;
            }
            return(result);
        }
        public ResponseResult <Owner> Get(int id)
        {
            ResponseResult <Owner> result = new ResponseResult <Owner>();

            try
            {
                OwnerService ownerService = new OwnerService();
                result.Result = ownerService.GetOwner(id);
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Message   = e.Message;
            }
            return(result);
        }
        public ResponseResult <List <Owner> > searchUsers([FromQuery] string Para)
        {
            ResponseResult <List <Owner> > result = new ResponseResult <List <Owner> >();

            try
            {
                OwnerService ownerService = new OwnerService();
                result.Result = ownerService.SearchUsers(Para);
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Message   = e.Message;
            }
            return(result);
        }
        public ResponseResult <Cookie> Put([FromBody] UpdateDogInfo updateDogInfo)
        {
            ResponseResult <Cookie> result       = new ResponseResult <Cookie>();
            OwnerService            ownerService = new OwnerService();

            try
            {
                result.Result    = null;
                result.IsSuccess = ownerService.UpdateInfo(updateDogInfo);
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Message   = e.Message;
            }
            return(result);
        }
Esempio n. 17
0
        public async void GetAllOwnersNoAutoMapper_Sorts_Results_By_Name()
        {
            // Arrange
            var mockOwnerRepository   = new Mock <IOwnerRepository>();
            var mockRepositoryWrapper = new Mock <IRepositoryWrapper>();


            var dylan = new Owner()
            {
                Id       = Guid.NewGuid(),
                Name     = "Dylan",
                Address  = "my address",
                Accounts = new List <Account>()
            };

            var crystal = new Owner()
            {
                Id       = Guid.NewGuid(),
                Name     = "Crystal",
                Address  = "my address",
                Accounts = new List <Account>()
            };

            var ownersToReturn = new List <Owner>()
            {
                dylan,
                crystal
            }.AsQueryable();

            mockOwnerRepository.Setup(m => m.FindAll()).Returns(ownersToReturn);

            var mockLogger = NullLogger <OwnerService> .Instance;

            var mockMapper = new Mock <IMapper>();

            // Act
            var ownerService = new OwnerService(mockRepositoryWrapper.Object, mockLogger, mockMapper.Object);
            var result0      = await ownerService.GetAllOwnersNoAutoMapperAsync();

            var result = result0.ToList();

            // Assert
            Assert.Equal(2, result.Count());
            Assert.True("Crystal" == result[0].Name);
            Assert.True("Dylan" == result[1].Name);
        }
        public static OwnerBankDetail GetOwnerBankDetailById(int BankId)
        {
            OwnerBankDetail bankDetail = new OwnerBankDetail();

            var Data = OwnerService.GetOwnerBankDetail(BankId);

            if (Data != null)
            {
                bankDetail.Id            = Data.Id;
                bankDetail.BankName      = Data.BankName;
                bankDetail.Branch        = Data.Branch;
                bankDetail.AccountNumber = Data.AccountNumber;
                bankDetail.IFSC          = Data.IFSC;
            }

            return(bankDetail);
        }
Esempio n. 19
0
        public void CreateOwnerRepositoryCalls()
        {
            var ownerRepo = new Mock <IOwnerRepository>();
            var petRepo   = new Mock <IPetRepository>();
            var service   = new OwnerService(ownerRepo.Object, petRepo.Object);

            var owner = new Owner
            {
                FirstName = "fname",
                LastName  = "lname"
            };

            service.CreateOwner(owner);

            ownerRepo.Verify(repo => repo.Create(It.IsAny <Owner>()), Times.Once());
            petRepo.Verify(repo => repo.Create(It.IsAny <Pet>()), Times.Never());
        }
Esempio n. 20
0
        public async Task CreateAsync_OwnerValidationSucceed_CreatesOwner()
        {
            // Arrange
            var owner    = new OwnerUpdateModel();
            var expected = new Owner();

            var ownerDAL = new Mock <IOwnerDAL>();

            ownerDAL.Setup(x => x.InsertAsync(doctor)).ReturnsAsync(expected);

            var ownerService = new OwnerService(doctorDAL.Object);

            // Act
            var result = await ownerService.CreateAsync(owner);

            // Assert
            result.Should().Be(expected);
        }
        public static OwnerAddress GetAddressById(int AddressId)
        {
            OwnerAddress ownerAddress = new OwnerAddress();

            var Data = OwnerService.GetOwnerAddressById(AddressId);

            if (Data != null)
            {
                ownerAddress.Id       = Data.Id;
                ownerAddress.Street1  = Data.Street1;
                ownerAddress.Street2  = Data.Street2;
                ownerAddress.City     = Data.City;
                ownerAddress.PostCode = Data.PostCode;
                ownerAddress.StateId  = Data.StateId;
            }

            return(ownerAddress);
        }
Esempio n. 22
0
        public ActionResult DoOwnerLogin(Owner owner)
        {
            var ownerService = new OwnerService();

            owner.Id = ownerService.CheckAccount(owner);
            if (owner.Id == 0)
            {
                return(Json(new ResultInfo(false, "用户名或密码错误", null)));
            }

            Session["Account"] = new AccountInfo()
            {
                Id      = owner.Id,
                Name    = owner.Name,
                IsAdmin = false
            };
            return(Json(new ResultInfo(true, "登录成功", null)));
        }
        public GenderSeperatedViewModel GetAnimals()
        {
            GenderSeperatedViewModel animalViewModel = new GenderSeperatedViewModel();

            try
            {
                _ownerService = new OwnerService();
                _business     = new Business();

                var list = _ownerService.GetAllOwnerList();                                 // Call service that pulls out all owner data along with their animals and prepare a owner list
                List <OwnerModel> ownerViewModel = GetAllOwnerAnimalsViewModel(list);       //Convert result into owner model
                animalViewModel = _business.GetGenderSeparatedOwnerCatList(ownerViewModel); //Get result view model consisting both models 1. Male, 2. Female
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(animalViewModel);
        }
Esempio n. 24
0
        public async Task OwnerService_RetrieveUknownGenderIsNull_True()
        {
            // Arrange
            // See Constructor/Setup above

            IOwnerService ownerService = new OwnerService(_loggerMock.Object,
                                                          _urlHelper.Object,
                                                          _httpClientMock,
                                                          _deserializer.Object,
                                                          _repositoryOwner,
                                                          _sortOwner);

            // Act
            IList <Owner> list = await ownerService.GetByGender("Unknown", true);

            // Assert
            Assert.NotNull(list);
            Assert.True(list.Count == 0);
        }
Esempio n. 25
0
        public async Task ValidateAsync_OwnerExists_DoesNothing()
        {
            // Arrange
            var ownerContainer = new Mock <IOwnerContainer>();

            var owner         = new Owner();
            var ownerDAL      = new Mock <IOwnerDAL>();
            var ownerIdentity = new Mock <IOwnerIdentity>();

            ownerDAL.Setup(x => x.GetAsync(ownerIdentity.Object)).ReturnsAsync(owner);

            var ownerGetService = new OwnerService(ownerDAL.Object);

            // Act
            var action = new Func <Task>(() => ownerGetService.ValidateAsync(ownerContainer.Object));

            // Assert
            await action.Should().NotThrowAsync <Exception>();
        }
Esempio n. 26
0
        static void Main(string[] args)
        {
            IPetRepository petRepository = new PetRepository();

            IPetTypeRepository petTypeRepository = new PetTypeRepository();

            IOwnerRepository ownerRepository = new OwnerRepository();

            IPetService petService = new PetService(petRepository, ownerRepository, petTypeRepository);

            IOwnerService ownerService = new OwnerService(ownerRepository, petRepository);

            FakeDB.InitData();



            Printer print = new Printer(petService, ownerService);

            print.PrintMenu();
        }
        public void GetAllOwners_Sorts_Results_By_Name()
        {
            //test one thing and one thing only usually

            //Arrange
            var mockOwnerRepository = new Mock <IOwnerRepository>();
            var mockLogger          = NullLogger <OwnerService> .Instance;
            //var logger = new Mock<ILogger<OwnerService>>();
            // you can have strict or loose mockup

            var mockMapper = new Mock <IMapper>();

            var ownerService = new OwnerService(mockOwnerRepository.Object, mockLogger, mockMapper.Object);

            //Act
            var result = ownerService.GetAllOwners();

            //Assert
            Assert.Equal(2, result.Count());
        }
Esempio n. 28
0
        /// <summary>
        /// Setup the test
        /// </summary>
        public OwnerUnitTest()
        {
            DbContextOptions <DbAppContext> options      = new DbContextOptions <DbAppContext>();
            Mock <DbAppContext>             dbAppContext = new Mock <DbAppContext>(null, options);

            /*
             *
             * Here you will need to mock up the context.
             *
             * ItemType fakeItem = new ItemType(...);
             *
             * Mock<DbSet<ItemType>> mockList = MockDbSet.Create(fakeItem);
             *
             * dbAppContext.Setup(x => x.ModelEndpoint).Returns(mockItem.Object);
             *
             */

            OwnerService _service = new OwnerService(null, dbAppContext.Object);

            _Owner = new OwnerController(_service);
        }
        public ResponseResult <Cookie> Login([FromBody] Login owner)
        {
            ResponseResult <Cookie> result = new ResponseResult <Cookie>();

            try
            {
                OwnerService ownerService = new OwnerService();
                result.Result = ownerService.Login(owner);
                if (result.Result.UserId == 0)
                {
                    result.IsSuccess = false;
                    result.Message   = "Incorrect RegNo Or Password";
                }
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Message   = e.Message;
            }
            return(result);
        }
Esempio n. 30
0
        static void Main(string[] args)
        {
            ////Init Repositories
            //IRepository<Pet> petRepo = new PetRepository();
            //IRepository<Owner> ownerRepo = new OwnerRepository();

            ////Init Services
            IPetService   petService   = new PetService(petRepo);
            IOwnerService ownerService = new OwnerService(ownerRepo);

            //init UI - Leaf And Branch Menuitems
            SortedList <int, IMenuItem> options = new SortedList <int, IMenuItem>();

            options.Add(1, new BranchMenuItem("Create", GetCreateOptions(petService, ownerService)));
            options.Add(2, new BranchMenuItem("Read", GetReadOptions(petService, ownerService)));
            options.Add(3, new BranchMenuItem("Update", GetUpdateOptions(petService, ownerService)));
            options.Add(4, new BranchMenuItem("Delete", GetDeleteOptions(petService, ownerService)));

            BranchMenuItem main = new BranchMenuItem(
                "                                                                           \n" +
                "       _____               _____           ____   ____             _____   \n" +
                "   ___|\\    \\          ___|\\    \\         |    | |    |        ___|\\    \\  \n" +
                "  /    /\\    \\        |    |\\    \\        |    | |    |       |    |\\    \\ \n" +
                " |    |  |    |       |    | |    |       |    | |    |       |    | |    |\n" +
                " |    |  |____|       |    |/____/        |    | |    |       |    | |    |\n" +
                " |    |   ____        |    |\\    \\        |    | |    |       |    | |    |\n" +
                " |    |  |    |       |    | |    |       |    | |    |       |    | |    |\n" +
                " |\\ ___\\/    /|  ___  |____| |____|  ___  |\\___\\_|____|  ___  |____|/____/|\n" +
                " | |   /____/ | |   | |    | |    | |   | | |    |    | |   | |    /    | |\n" +
                " \\| ___|    | / |___| |____| |____| |___|  \\|____|____| |___| |____|____|/ \n" +
                "    \\( |____|/          \\(     )/             \\(   )/           \\(    )/   \n" +
                "     '   )/              '     '               '   '             '    '    \n" +
                "         '                                                                 \n" +
                "  -The PetShop\n",
                options);

            main.display();
            Console.Clear();
        }