Exemplo n.º 1
0
        public async Task <bool> CreateOfferAsync(string authorId, string estateId, OfferCreateServiceModel model)
        {
            if (model.OfferType == null || string.IsNullOrEmpty(authorId) || string.IsNullOrEmpty(estateId))
            {
                throw new ArgumentNullException(InvlidMethodParameterMessage);
            }

            OfferType parsedEnum = model.OfferType == GlobalConstants.OfferTypeSaleName ? OfferType.Sale : OfferType.Rental;

            string referenceNumber = await this.referenceNumberGenerator.GenerateOfferReferenceNumber(model.OfferType, estateId);

            var author = await this.userServices.GetUserById(authorId);

            var offer = this.mapper.Map <Offer>(model);

            offer.Author          = author;
            offer.AuthorId        = authorId;
            offer.RealEstateId    = estateId;
            offer.OfferType       = parsedEnum;
            offer.ReferenceNumber = referenceNumber;
            offer.IsOfferActive   = true;

            await this.context.Offers.AddAsync(offer);

            var changedRows = await this.context.SaveChangesAsync();

            if (changedRows == 0)
            {
                throw new InvalidOperationException(UnsuccessfullOfferCreationMessage);
            }

            return(true);
        }
Exemplo n.º 2
0
        public async Task CreateOfferShoulReturnTrue()
        {
            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            string realEstateId = "myRealEstateId4";
            string authorId     = "coolUniqueId3";
            var    offerToAdd   = new OfferCreateServiceModel
            {
                OfferType               = "Продажба",
                Comments                = "Some important comments",
                ContactNumber           = "0888607796",
                AgentName               = "Pesho",
                OfferServiceInformation = "Some Owner telephone number 012345678"
            };

            var actualResult = await serviceInstance.CreateOfferAsync(authorId, realEstateId, offerToAdd);

            Assert.IsTrue(actualResult, ExpectedTrueTestResultMessage);
        }
Exemplo n.º 3
0
        public void CreateOfferShoulThrowWexeptionIfRealEstateIdIsInvalid()
        {
            var serviceInstance = new OfferServices(context,
                                                    imageServices.Object,
                                                    cloudinaryServices.Object,
                                                    userServices.Object,
                                                    referenceNumberGenerator.Object,
                                                    mapper
                                                    );

            string invalidRealEstateId = "";
            string authorId            = "coolUniqueId3";
            var    offerToAdd          = new OfferCreateServiceModel
            {
                OfferType     = "Продажба",
                Comments      = "Some important comments",
                ContactNumber = "0888607796",
            };

            Assert.ThrowsAsync <ArgumentNullException>(async() => await serviceInstance.CreateOfferAsync(authorId, invalidRealEstateId, offerToAdd), ArgumentNullExceptonMessage);
        }